View Full Version : Create and parse new templates
I'm trying to add a new template to my layout. The help says "When adding custom templates, in order to have them parsed, you must also write PHP code to call them." How I do that? And how I use my new template in another one?
nico_swd
08-04-2007, 11:55 PM
Have a look at this article.
https://vborg.vbsupport.ru/showthread.php?t=62164
Thank you very much for your answer, nico_swd, but this is not what I need to do (in fact, I knew that article ;)). What I need to do is to use a custom template inside other (standard) ones. For instance, you see in the example provided in that article that they include the contents of the header template just by including the $header variable. That's what I need to do, create a new template (for instance, my_template) that I can include in other templates simply by writting the variable $my_template.
I assume, I need to write a plug-in in some place to process the contents of the template and store them in that variable?
EnIgMa1234
08-05-2007, 01:06 AM
Your first need to cache the template then parse it.
The plugin hooks are called:
cache_templates
parse_templates
Your first need to cache the template then parse it.
The plugin hooks are called:
cache_templates
parse_templates
Thank you very much Enigma. This is very useful, thank you again.
Could you, please, point me where I can find an example of those plugins implemented? Lots of thanks in advance.
EnIgMa1234
08-05-2007, 01:48 AM
In cache templates
$globaltemplates = array_merge($globaltemplates, array('YOURTEMPLATE'));
In parse templates
eval('$YOURVARIABLE = "' . fetch_template('YOURTEMPLATE') . '";');
Then you can use $YOURVARIABLE
Eikinskjaldi
08-05-2007, 01:53 AM
When including one template in another what you actually do is eval the inner tamplate to a variable and then pass that variable to the outer template.
So for instance say you had a really simple innerTemplate that wraps <tr> tags around a series of entries
you might have this code
foreach ($foo as $bar)
eval('$innerBit .= "'.fetch_template('tr_wrap_bit').'";');
where the tr_wrap_bit sees the $bar variable.
Now you have a string ($innerBit) which contains a concatenation of the innerTemplate. You can simply then pass this variable to the next layer of template.
Thank you lots, Eikinskjaldi and Enigma. All this information has helped me a lot, and I've been able to complete my litlle project. I owe you both a free drink ;)
BTW, just saw at the main page od the forums... Happy birthday Enimga!!! Now I owe you two drinks :p
vBulletin® v3.8.12 by vBS, Copyright ©2000-2025, vBulletin Solutions Inc.