Exporting variables to the view templates
View Template files are those with the extension template.php (this is different from Site Template (Theme) in /templates). View Template files are located in /apps/{name of your app}/folders.
To export variables to the view templates, simply call loadTemplateFile method. For example: the following method displays an RSS feed of the content of your application.
public function RSS() { global $SystemConfig, $SiteTemplate; header('Content-Type: application/rss+xml; charset=UTF-8'); // the following variables will be exported to the template file $rss_blog_title= $this->getConfig('str_title'); $rss_author_name = $this->getConfig('str_author_name'); $rss_author_email = $this->getConfig('str_author_email'); $rss_desc = $this->getConfig('str_description'); $rss_maxposts= $this->getConfig('int_max_entries_in_rss'); // Maximum number of entries to be displayed in the RSS file $total_item_count = $this->getTotalItemCount(true); // The limit is introduced to prevent memory exhaustion // hardcode all item limit if there's no limit specified if ($rss_maxposts == 0 || $rss_maxposts > $total_item_count) $rssmax_posts = $total_item_count; if ($rss_maxposts > 500) $rss_maxposts = 500; $latestposts = $this->getAllItems('*','status > 0', 0,$rss_maxposts,'date_created','DESC'); $css_path = '/templates/'.$SiteTemplate->getDefaultTemplateName().'/rss.css'; // Now load the template file $this->loadTemplateFile('rss',compact(array_keys(get_defined_vars()))); }
The key is in the following code
$this->loadTemplateFile('rss',compact(array_keys(get_defined_vars())));
Now, in your template file rss.template.php, you will have access to those variables as if it was local. For example:
echo $rss_blog_title;