I’m trying to make a little plugin that caches templates on its own.
Instead of using the following line, which caches the template per URL:
{embed="group/template" cache="yes" refresh="60"}I’m trying to make an add-on that parses and caches the template itself:
{exp:myaddon source="group/template" myrefresh="60"}The idea is that the add-on will get the template from exp_templates, parse it and save it in a text file for 60 minutes. If a cache is available it will return the cache. The advantage is that the template is not cached per URL.
My question is: After I get ‘template_data’ from the database, what function can I use to parse the data?
I tried TMPL->parse_variables but this doesn’t work. The output still has all the EE tags.
Thank you.
Thanks, this has been really helpful.
I am now using the following code to parse a template in my module:
$this->EE->TMPL->fetch_and_parse($template_group, $template, $sub = FALSE, $site_id);
$output = $this->EE->TMPL->parse_globals($this->EE->TMPL->final_template);Then I replace variables with parse_variables_row. With the following {var} gets replaced with ‘abc’:
$variables = array('var' => 'abc');
$output = $this->EE->TMPL->parse_variables_row($output, $variables);My two questions:
Is there also a way to parse embedded variables in the template, so ones like: {embed:var} ?
What is the $sub for? If I set it to TRUE the output is empty.
Thanks!
Yes, kind of. If you pass $sub = FALSE then it will parse any emebbed templates that are in the master template. The embed vars will be parsed naturally. If you are calling the embed tempate not in the context of the master template then you will have to manually parse them yourself.
You want $sub to be false. It tells the parser if it is operating on the master template or a sub template (embeds). Only the master template output is assigned to $this->EE->TMPL->final_template.
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.