PDA

View Full Version : Call a template in another template!


Mr Pink
02-26-2007, 10:42 AM
Hi, I've a template called "mytemplatetest", and I want call it in another template, if possible. I've try with $mytemplatetest (viewing the called $footer, $header, etc., templates), but it doesn't work.
Can you please help me?



Best regards,
Mr Pink (aka Norman)
Web City Forum Online
http://www.web-city.it/

CyberAlien
02-26-2007, 11:10 AM
You can't include other template files in a template file, you need to parse it separately in php code.

If you want to include that template on every page, then open global.php, find this:$globaltemplates = array_merge($globaltemplates, array(
// the really important ones
'header',
'footer',
'headinclude',
and add your template name to that array

Then find this:// parse some global templates
eval('$gobutton = "' . fetch_template('gobutton') . '";');
eval('$spacer_open = "' . fetch_template('spacer_open') . '";');
eval('$spacer_close = "' . fetch_template('spacer_close') . '";');
and add after it:eval('$mytemplatetest = "' . fetch_template('mytemplatetest') . '";');
Then you can use $mytemplatetest in all templates.

Or write a hack that uses "parse_templates" hook to parse your template.

Mr Pink
02-26-2007, 11:23 AM
Thanks really for your reply, CyberAlien.
So I need to put the entire code into the navbar template (I'm making a style, and I don't want use external files/modifications). :(

CyberAlien
02-26-2007, 12:23 PM
There is another solution: replacements. Create replacement like "<my-header>", put your code in it, then use <my-header> in navbar template. < and > in replacement name are there to make sure there isn't any similar text within posts so nothing else will be replaced.

Mr Pink
02-26-2007, 12:33 PM
The problem is that I'm trying to do a vB style that I'll posting here like a simple release (I'm doing it for learn coding and take familiarity with vB), so I can't use other resources rather then the simple template modification.

CyberAlien
02-26-2007, 12:37 PM
Replacements are simple template modifications that you can safely use.

Mr Pink
02-26-2007, 12:42 PM
If a user will download the style, then he will need to add the replacement, right?

CyberAlien
02-26-2007, 12:46 PM
No, it will be in xml file.

Mr Pink
02-26-2007, 12:51 PM
Oh, so I can use them. Great! I thought that users had to add them by themselves! Ok ok, great! Thanks again man. Now my problem is that in the other thread in this forum! :)