Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

{nocache} around {block} gets ignored for {block} in child template since 3.1.28 #371

Closed
strikernl opened this issue Jun 7, 2017 · 4 comments

Comments

@strikernl
Copy link

strikernl commented Jun 7, 2017

When using {nocache} tags around a {block} that gets inherited by a child template, before 3.1.28 the code in the child block would correctly not be cached. Since 3.1.28 (and still in 3.1.31) this behaviour has changed.

Testcase:

PHP

<?php

require('smarty/libs/Smarty.class.php');

$tpl = new Smarty();
$tpl->setCacheDir('cache');
$tpl->setCaching(Smarty::CACHING_LIFETIME_CURRENT);
$tpl->display('page1.tpl');

page1.tpl

{extends file='page2.tpl'}

{block loop}
{for $i=1 to 10}
{$i}..
{/for}
{/block}

page2.tpl

Test1

{nocache}
{block loop}
{for $i=1 to 2}
{$i}..
{/for}
{/block}
{/nocache}

Test2

Expected result, 3.1.27 (cache/*.page1.tpl.php)

if ($_valid && !is_callable('content_5937f17cda34f5_77254665')) {
function content_5937f17cda34f5_77254665 ($_smarty_tpl) {
?>
Test1



<?php $_smarty_tpl->tpl_vars['i'] = new Smarty_Variable;$_smarty_tpl->tpl_vars['i']->step = 1;$_smarty_tpl->tpl_vars['i']->total = (int) ceil(($_smarty_tpl->tpl_vars['i']->step > 0 ? 10+1 - (1) : 1-(10)+1)/abs($_smarty_tpl->tpl_vars['i']->step));
if ($_smarty_tpl->tpl_vars['i']->total > 0) {
for ($_smarty_tpl->tpl_vars['i']->value = 1, $_smarty_tpl->tpl_vars['i']->iteration = 1;$_smarty_tpl->tpl_vars['i']->iteration <= $_smarty_tpl->tpl_vars['i']->total;$_smarty_tpl->tpl_vars['i']->value += $_smarty_tpl->tpl_vars['i']->step, $_smarty_tpl->tpl_vars['i']->iteration++) {
$_smarty_tpl->tpl_vars['i']->first = $_smarty_tpl->tpl_vars['i']->iteration == 1;$_smarty_tpl->tpl_vars['i']->last = $_smarty_tpl->tpl_vars['i']->iteration == $_smarty_tpl->tpl_vars['i']->total;?>
<?php echo $_smarty_tpl->tpl_vars['i']->value;?>
..
<?php }} ?>



Test2
<?php }
}

Actual result, since 3.1.28

function content_5937f15bc20167_08197167 ($_smarty_tpl) {
?>
Test1



1..
2..
3..
4..
5..
6..
7..
8..
9..
10..




Test2
<?php }
}
@implico
Copy link

implico commented Jun 20, 2017

+1 for fixing this issue
Generally, a lot of issues arose in the area of caching&inheritance, another case (using the previous example), if you set page1.tpl to:

{extends file='page2.tpl'}

{block loop}
  {custom_plugin parameter="abc"}
{/block}

Then the cached output code contains reference to the smarty_function_custom_plugin(... and fails on execution.

@AnrDaemon
Copy link
Contributor

If you don't want block contents to be cached, use nocache flag for the block.

@uwetews
Copy link
Contributor

uwetews commented Nov 29, 2017

Before 3.1.28 template inheritance was processed during compile time. This had a couple of restrictions.
Since 3.1.28 this is a run time process.
But as now the compiled files for parent and child templates are created independent from each other the child does not know which blocks called nocache in the parent.

@AnrDaemon
Adding the nocache flag in {block} is not a general solution as child and parent templates with different nocache settings could be combined for example with the extends: resource.
I am currently implementing a solution for this problem.
This does address also the related problem with plugins inside {block}

uwetews pushed a commit that referenced this issue Mar 28, 2018
@wisskid
Copy link
Contributor

wisskid commented Feb 6, 2020

This has been fixed

@wisskid wisskid closed this as completed Feb 6, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants