What is the best way to "send" a PHP variable between templates? I have an array $myArray
that I create in my index.html
template. Then I have a template which goes to fetch data from an external API, and store the items in $myArray
. And then I've turned on caching for this template, so I won't have to churn through the API request on every load. Then back at the index.html
I want to output stuff from $myArray
.
Basically it would look something like this:
//index.html:
<?php global $myArray; ?>
{embed="include/api"}
<?php
foreach ($myArray as $m) {
//output
} ?>
//api.html:
global $myArray;
$myArray = getAPIdata(); //getAPIdata just fetches stuff and returns the array
Now, this doesn't work of course. But I don't know why. And I don't have any other ideas on how to accomplish this. Especially since I want caching on my api.html
template.