How does smarty implement I ++ on html pages? How does smarty implement I ++?
How can I translate the following C # code into the code under smarty?
<% int i_count = 0; foreach (GridViewRow row in this.GridView1.Rows) { if (i_count%4 == 0) {%> .1..
<% } else {%>
.2..
<% } i_count ++ ; }%>
I wrote this, but ERROR
{assign var="i_count"} {foreach from=$row item=item} {if $i_count mod 4} .2..
{else}
.1..
{/if} {$i_count + 1 } {/foreach}
How can I write it? Is it my I ++ error?
Reply to discussion (solution)
Why do you want to write it like this? In smarty foreach, you can obtain the {foreach from = $ var key = k item = v} of the current key}
This k is enough.
{assign var="i_count" value=0} {foreach from=$row item=item} {if $i_count mod 4} .2..
{else}
.1..
{/if} {assign var="i_count" value=$i_count+1} {/foreach}
No test. if not, use ''for $ I _count + 1.
Plain Text code? 1234567891011121314 {assign var = "I _count" value = 0} {foreach from = $ row item = item} {if $ I _count mod 4 }......
It seems to be caused by '', but why does my code execute the content in the first p for the first time and then all the content in the second p?
{if $i_count mod 4 == 0} .1..
{else}
.2..
{/if}
{foreach from=$row item=item key=i_count} {if $i_count mod 4} .2..
{else}
.1..
{/if}
{foreach from=$row item=item key=i_count}{if ($i_count mod 4)==0}.2..
{else}
.1..
{/if}
This sentence can be written in this way.
{if ($i_count mod 4) eq 0}