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

Optimized subtemplate compilation with nocache variables

 
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 -> Feature Requests
View previous topic :: View next topic  
Author Message
mimos
Smarty Rookie


Joined: 15 Oct 2016
Posts: 7

PostPosted: Fri Mar 06, 2020 12:11 am    Post subject: Optimized subtemplate compilation with nocache variables Reply with quote

Hi,

I stumbled upon the following case where I could change the code to a version with worse readability/usability to get an optimized result. I think in this case smarty could maybe automatically do the optimization itself so using the nicer code would be possible:

First the version with the nice code:
php code:
Code:

include ...;
$smarty = new Smarty;
$smarty->caching = true;
$smarty->debugging = true;
$smarty-assign('uncached', 'test', true);
$smarty->display('template.tpl');

template.tpl:
Code:

{include file="subtemplate.tpl" other_name=$uncached}

subtemplate.tpl:
Code:

{$other_name}


When I run this I see the two templates seperately in the debug view every time, so the subtemplate afaik gets loaded separately every time.

To optimize that I can change template.tpl:
Code:

{assign "other_name" $uncached}
{include file="subtemplate.tpl"}


Now the debug window only shows template.tpl so the subtemplate gets integrated into it which should be better for the loading times.

I'd be happy if you could teach smarty to get the same result using the nicer code from the top Smile .

Thanks,
Mimos
Back to top
View user's profile Send private message
AnrDaemon
Administrator


Joined: 03 Dec 2012
Posts: 1785

PostPosted: Mon Mar 09, 2020 1:29 am    Post subject: Reply with quote

That's not quite true. All templates are cached separately, unless you explicitly ask for inline include. However, since your "subtemplate" contains a "nocache" variable, it won't get cached.
Instead of guessing from debug console output, just go down the Smarty cache path and look at the templates cached.
Back to top
View user's profile Send private message
mimos
Smarty Rookie


Joined: 15 Oct 2016
Posts: 7

PostPosted: Fri Aug 21, 2020 4:25 pm    Post subject: Reply with quote

Sorry for replying this late. Thanks for your explanations and sorry for my unneeded post.
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 -> Feature Requests 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