|
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 |
CrazyTemplate Smarty Rookie
Joined: 12 Sep 2011 Posts: 31
|
Posted: Thu Nov 05, 2015 9:28 pm Post subject: Complex child template includes with cache |
|
|
Hello,
I have a complex template structure and I would appreciate some help with caching.
I load a main template (which has a header and a footer) via:
Code: |
$subTemplate = "homepage.html";
$smarty->display('extends:template.html|'.$subTemplate, $_action);
|
The above main template (template.html) loads the subTemplate (homepage.html) as a block inside it:
Code: |
{block name=content}{/block}
|
Now, inside the homepage.html block code, I also include a sub-sub template via:
Code: |
{include file='results.html'}
|
The results.html has a foreach loop that generates a lot of little div's by loading a single template for all those divs like:
Code: |
{foreach $RESULTS as $r}<div>{include 'singleResult.html'}</div>{/foreach}
|
When cache is enabled system-wide, how do I force different "singleResult.html" cache files? So when those little divs are generated in other pages, I can just load the same little templates for them, instead of regenerating new ones?
The $RESULTS array contains my data objects which are rendered in the template singleResult, each object has a unique ID, is it possible to use that somehow?
Any help would be appreciated.
Thank you. |
|
Back to top |
|
AnrDaemon Administrator
Joined: 03 Dec 2012 Posts: 1785
|
|
Back to top |
|
CrazyTemplate Smarty Rookie
Joined: 12 Sep 2011 Posts: 31
|
Posted: Thu Nov 05, 2015 10:23 pm Post subject: |
|
|
Thank you for your quick reply!
I did read, but I think I don't quite understand some details and I'm getting confused about inheritance.
The {include} function as per the documentation example 7.51, says that by adding "caching" I can force the included template to be cached, regardless of the global setting.
But it doesn't explain what happens if this whole template is being called by a "nocache" parent template.
Is there some page in the docs that I missed about cache inheritance? |
|
Back to top |
|
AnrDaemon Administrator
Joined: 03 Dec 2012 Posts: 1785
|
Posted: Thu Nov 05, 2015 11:23 pm Post subject: |
|
|
Read it again then.
At the very beginning, before any examples, is the table of possible handler parameters.
Which includes both a cache_id and nocache parameters.
Also more about caching: http://www.smarty.net/docs/en/caching.tpl |
|
Back to top |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
Posted: Wed Nov 25, 2015 6:03 am Post subject: |
|
|
Code: | {include 'singleResult.html' cache_id=$foo caching} |
The above will create or load different cache files which identified by its cache_id value. |
|
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
|