Smarty counter variable is defined in parent file but incremented and used in child include file
P粉523335026
P粉523335026 2023-09-01 19:10:23
0
1
509
<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>
P粉523335026
P粉523335026

reply all(1)
P粉716228245

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

{assign var="counter" value=0}
{foreach ...} /* iterates at least 100 times */
    {assign var="counter" value=$counter+1}
    {include file='Second.tpl' counter=$counter}
{/foreach}

Second.tpl

{$counter} /* Check if counter increase */

{if $counter > 10} do-something {/if}

Notice. - I initialize $counter to zero.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template