|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
GeXus Smarty Rookie
Joined: 16 Aug 2006 Posts: 28
|
Posted: Sat Feb 03, 2007 4:10 am Post subject: Including dynamic template in another template |
|
|
I have one template that is being displayed from a php file, i want to then include this into another template... but when I try to include the php file, it just doesnt seem to work.. |
|
Back to top |
|
boots Administrator
Joined: 16 Apr 2003 Posts: 5611 Location: Toronto, Canada
|
Posted: Sat Feb 03, 2007 9:06 am Post subject: |
|
|
Hi.
Show us how you are trying to accomplish this. On its own, "doesn't work" is difficult to parse |
|
Back to top |
|
GeXus Smarty Rookie
Joined: 16 Aug 2006 Posts: 28
|
Posted: Sat Feb 03, 2007 6:31 pm Post subject: |
|
|
Okay
This is what i'm doing.
I have categories.php -> displaying to -> categories.tpl
then i have main.php -> main.tpl
I want to include the output from categories.tpl inside the main.tpl, but the categories.tpl has to be processed by the php.
So in the main.tpl I tried doing
Code: |
{include_php file='/path/categories.php'}
|
But I get
Fatal error: Cannot redeclare class smarty in /usr/local/lib/php/Smarty/Smarty.class.php on line 65
But i would like each page to work independantly as well, so I don't want to remove the declaration, and I dont think that will work either. |
|
Back to top |
|
boots Administrator
Joined: 16 Apr 2003 Posts: 5611 Location: Toronto, Canada
|
Posted: Sun Feb 04, 2007 12:49 am Post subject: |
|
|
You could probably do a require_once (or include_once) but you might want to consider using a singleton (or even better, a factory or even a registry) to instantiate your Smarty object. The basic idea is that each script would then do something like:
Code: | require_once 'SmartyFactory.php';
$smarty = SmartyFactory::getInstance(); |
where your factory creates a new instance (and configures it) only if one hasn't already been created -- otherwise it returns the previously created instance.
An example of the idea is here: http://www.phpinsider.com/smarty-forum/viewtopic.php?t=5300
HTH |
|
Back to top |
|
GeXus Smarty Rookie
Joined: 16 Aug 2006 Posts: 28
|
Posted: Sun Feb 04, 2007 3:16 pm Post subject: |
|
|
Perfect, thank you! |
|
Back to top |
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|