|
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 |
ndorphin Smarty Rookie
Joined: 24 Dec 2009 Posts: 15 Location: Berlin, Germany
|
Posted: Mon Jan 25, 2016 9:34 am Post subject: nocache blocks and effects on variables |
|
|
Hi,
here in this sample i would expect the output of 'abc' but the variable is always empty. I thought the unused {nocache} block in {if} condition couldn't affect the variable in {else} but it does. Question is bug or feature?
thanks for info.
ndorphin
{$test='abc'}
{if $doNot}
{nocache}
{$test='xyz'}
{/nocache}
{else}
{$test}
{/if}
Tested with 3.1.29 |
|
Back to top |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
Posted: Wed Jan 27, 2016 8:59 pm Post subject: |
|
|
This is an example of inconsistent use of using the same variable in cached and nocache mode.
The compiler has to produce different code for both cases.
If the variable was assigned by $smarty->assign() the variable and its nocache mode is known when it compiles for example {$test}.
In your example the compiler does first see {$test='abc'} and it will generate code which will be only be executed when the compiled template is rendered, but the variable will not be assigned when the cached template is called.
Later the compiler sees {nocache}
{$test='xyz'}
{/nocache} This will generate an assignment of $test as nocache code which might never be executed because of the value of $doNot.
However the compiler will now set a flag that all future references of $test shall be compiled in nocache mode which happens with {$test} in the else section. In your case it will result in an unassigned value.
The compiler is to be as smart as possible but it can not make assumptions about the run time template code flow.
To say it in one sentence it's an ambiguous use of using same variable in both caching modes.
Gruß aus Hamburg |
|
Back to top |
|
ndorphin Smarty Rookie
Joined: 24 Dec 2009 Posts: 15 Location: Berlin, Germany
|
Posted: Sat Jan 30, 2016 1:15 pm Post subject: |
|
|
Ok, i understand. Thanks for clearing this, Uwe.
Schönen Tag dann noch! |
|
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
|