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

Complex child template includes with cache

 
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
CrazyTemplate
Smarty Rookie


Joined: 12 Sep 2011
Posts: 31

PostPosted: Thu Nov 05, 2015 9:28 pm    Post subject: Complex child template includes with cache Reply with quote

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
View user's profile Send private message Visit poster's website
AnrDaemon
Administrator


Joined: 03 Dec 2012
Posts: 1785

PostPosted: Thu Nov 05, 2015 9:51 pm    Post subject: Reply with quote

Did you read http://www.smarty.net/docs/en/language.function.include.tpl ? It has at least two answers to your question.
Back to top
View user's profile Send private message
CrazyTemplate
Smarty Rookie


Joined: 12 Sep 2011
Posts: 31

PostPosted: Thu Nov 05, 2015 10:23 pm    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
AnrDaemon
Administrator


Joined: 03 Dec 2012
Posts: 1785

PostPosted: Thu Nov 05, 2015 11:23 pm    Post subject: Reply with quote

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


Joined: 22 Nov 2006
Posts: 5068
Location: Hamburg / Germany

PostPosted: Wed Nov 25, 2015 6:03 am    Post subject: Reply with quote

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
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