Smarty Forum Index Smarty
The discussions here are for Smarty, a template engine for the PHP programming language.

Re using same template with different data

 
Post new topic   Reply to topic    Smarty Forum Index -> Smarty Development
View previous topic :: View next topic  
Author Message
starsky
Smarty n00b


Joined: 03 Mar 2004
Posts: 4

PostPosted: Wed Mar 03, 2004 10:01 am    Post subject: Re using same template with different data Reply with quote

Hi all,

I would like to know the best way to do so :

Code:
myincludedtemplate1.tpl :
     data1 : {$data1}
     data2 : {$data2}

myincludedtemplate2.tpl :
     content1 : {$data1}
     content2 : {$data2}

myincludertemplate.tpl :
      <table>
     {include file="myincludedtemplate1.tpl"}
     {include file="myincludedtemplate2.tpl"}
      </table>


But with different data in the 2 included files. Well, my constraint is actually to have in the same page a lot of variables with the same name, like $title, $content...
If someone could show me a way to do so, precompilation of included templates, other ways???

Thanks in advance
Back to top
View user's profile Send private message
boots
Administrator


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

PostPosted: Wed Mar 03, 2004 7:16 pm    Post subject: Re: Re using same template with different data Reply with quote

starsky wrote:
Code:
myincludedtemplate1.tpl :
     data1 : {$data1}
     data2 : {$data2}

myincludedtemplate2.tpl :
     content1 : {$data1}
     content2 : {$data2}

myincludertemplate.tpl :
      <table>
     {include file="myincludedtemplate1.tpl"}
     {include file="myincludedtemplate2.tpl"}
      </table>


But with different data in the 2 included files. Well, my constraint is actually to have in the same page a lot of variables with the same name, like $title, $content...

Perhaps this:

You can pass vars through the include. Here, I assign $data1 and $data2 to various members of different arrays. Adapt to your needs.
Code:
{include file="myincludedtemplate1.tpl" data1=$a.data1 data2=$a.data2}
{include file="myincludedtemplate2.tpl" data1=$b.data1 data2=$b.data2}

I usually only ever assign a single variable to Smarty (the payload) which is a big array of vars. In other words, consider using arrays to handle "namespaces".
Back to top
View user's profile Send private message
starsky
Smarty n00b


Joined: 03 Mar 2004
Posts: 4

PostPosted: Thu Mar 04, 2004 8:52 am    Post subject: Reply with quote

Thanks for your answer...

Actually the more simple to me is to fetch in a variable my first template, then clear the cache(if using the same template) and fetch the second template with the other data.

I'm not used to the "template spirit", but I guess it's a good way to do so!
Back to top
View user's profile Send private message
boots
Administrator


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

PostPosted: Thu Mar 04, 2004 5:21 pm    Post subject: Reply with quote

You don't have to clear the cache (particularly if multiple requests for the data will ensue). Simply use multiple cache_id's. It's in the manual, but unfortunately, I can't provide the link at the moment.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Smarty Forum Index -> Smarty Development 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