|
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 |
starsky Smarty n00b
Joined: 03 Mar 2004 Posts: 4
|
Posted: Wed Mar 03, 2004 10:01 am Post subject: Re using same template with different data |
|
|
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 |
|
boots Administrator
Joined: 16 Apr 2003 Posts: 5611 Location: Toronto, Canada
|
Posted: Wed Mar 03, 2004 7:16 pm Post subject: Re: Re using same template with different data |
|
|
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 |
|
starsky Smarty n00b
Joined: 03 Mar 2004 Posts: 4
|
Posted: Thu Mar 04, 2004 8:52 am Post subject: |
|
|
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 |
|
boots Administrator
Joined: 16 Apr 2003 Posts: 5611 Location: Toronto, Canada
|
Posted: Thu Mar 04, 2004 5:21 pm Post subject: |
|
|
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 |
|
|
|
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
|