Smarty Forum Index Smarty
The discussions here are for Smarty, a template engine for the PHP programming language.

Optimized subtemplate compilation with nocache variables

 
Post new topic   Reply to topic    Smarty Forum Index -> Feature Requests
View previous topic :: View next topic  
Author Message
mimos
Smarty Rookie


Joined: 15 Oct 2016
Posts: 6

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

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
Display posts from previous:   
Post new topic   Reply to topic    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