|
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 |
AnrDaemon Administrator
Joined: 03 Dec 2012 Posts: 1785
|
Posted: Thu Apr 09, 2015 2:09 am Post subject: Do included templates inherit compile_id? |
|
|
I was wondering for a moment.
Do included/extended templates inherit compile_id of the caller?
And related question, can I specify compile_id as a variable in template?
Let's say I have tree-like category menu that takes hell of a lot of time to build right, and a number of articles in a given category. The category id is used as compile_id for the menu, but articles, obviously, using their own compile_id (article id).
Category id is passed to the template as variable, can I use it to assign compile_id to menu? |
|
Back to top |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
Posted: Thu Apr 09, 2015 9:24 pm Post subject: |
|
|
You have wrong understanding of compile_id and cache_id.
The compile_id is used to keep different compilation results of same template separated. This is useful if you want for example use the same template source with different pre- or postfilters.
If caching is enabled you use article id as cache_id to create different cache files with the rendered output for each article.
Included templates do inherit the cache_id (and compile_id) of the caller by default. But you can create a separate cache file for the category menu by assigning the category to the cache_id attribute like
Code: | {inclunde file='category.tpl' cache_id=$category} |
see http://www.smarty.net/docs/en/language.function.include.tpl
Enabling caching and using cache_id's does just save the time for rendering the content.
Must time is spend for obtaining article and may be category data from a database and assign it to template variables. This is only necessary when the cache file is invalid.
Smarty::isCached() does solve this.
see http://www.smarty.net/docs/en/api.is.cached.tpl
Code: | if(!$smarty->isCached('article.tpl', null, $article_id)) {
// do article database calls, assign vars here
}
if(!$smarty->isCached('category.tpl', null, $category)) {
// do category database calls, assign vars here
}
$smarty->display('article.tpl', null, $article_id);
|
{extends} inherits always compile_id and cache_id from the calling template.
They have no function. |
|
Back to top |
|
AnrDaemon Administrator
Joined: 03 Dec 2012 Posts: 1785
|
Posted: Thu Apr 09, 2015 9:56 pm Post subject: |
|
|
Err, yes. Sorry for the confusion.
I don't know, what I have been writing.
I definitely did mean cache_id. |
|
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
|