Smarty counter variable is defined in parent file but incremented and used in child include file
P粉523335026
2023-09-01 19:10:23
<p>I like to define a counter variable in the parent tpl file (First.tpl) and increment and use it in the child include file (Second.tpl). </p>
<p>But the counter is no longer incremented. </p>
<p>First.tpl:</p>
<pre class="brush:php;toolbar:false;">{assign var = "counter" value = 1 scope = "global"}
{foreach ...} //iterates at least 100 times
{include file='Second.tpl'}
{/foreach}</pre>
<p>Second.tpl:</p>
<pre class="brush:php;toolbar:false;">{assign var="counter" value = $counter 1}
{$counter} //counter does not increase!
{if $counter > 10} do-something {/if} // if statement fails always!</pre></p>
This is the method I use to do something similar, increment a value inside a loop, and pass that value to the included file. try it:
First.tpl
Second.tpl
Notice. - I initialize
$counter
to zero.