Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

Including dynamic template in another template

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General
View previous topic :: View next topic  
Author Message
GeXus
Smarty Rookie


Joined: 16 Aug 2006
Posts: 28

PostPosted: Sat Feb 03, 2007 4:10 am    Post subject: Including dynamic template in another template Reply with quote

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
View user's profile Send private message
boots
Administrator


Joined: 16 Apr 2003
Posts: 5611
Location: Toronto, Canada

PostPosted: Sat Feb 03, 2007 9:06 am    Post subject: Reply with quote

Hi.

Show us how you are trying to accomplish this. On its own, "doesn't work" is difficult to parse Wink
Back to top
View user's profile Send private message
GeXus
Smarty Rookie


Joined: 16 Aug 2006
Posts: 28

PostPosted: Sat Feb 03, 2007 6:31 pm    Post subject: Reply with quote

Okay Smile

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
View user's profile Send private message
boots
Administrator


Joined: 16 Apr 2003
Posts: 5611
Location: Toronto, Canada

PostPosted: Sun Feb 04, 2007 12:49 am    Post subject: Reply with quote

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
View user's profile Send private message
GeXus
Smarty Rookie


Joined: 16 Aug 2006
Posts: 28

PostPosted: Sun Feb 04, 2007 3:16 pm    Post subject: Reply with quote

Perfect, thank you!
Back to top
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General All times are GMT
Page 1 of 1

 
Jump to:  
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
Protected by Anti-Spam ACP