Home > Article > Backend Development > How smarty implements i
How to implement i in html page with smarty
How to translate the following C# code into smarty code?
<% int i_count = 0; foreach (GridViewRow row in this.GridView1.Rows) { if (i_count%4 == 0) {%> <div>.1..<div><% } else {%> <div>.2..<div><% } i_count ++ ; }%>
{assign var="i_count"} {foreach from=$row item=item} {if $i_count mod 4} <div>.2..<div> {else} <div>.1..<div> {/if} {$i_count + 1 } {/foreach}
Why do you write it like this? In smarty foreach, you can get the current key {foreach from=$var key=k item=v}
This k is the one. Haha
{assign var="i_count" value=0} {foreach from=$row item=item} {if $i_count mod 4} <div>.2..<div> {else} <div>.1..<div> {/if} {assign var="i_count" value=$i_count+1} {/foreach}
Plain Text code?1234567891011121314{assign var="i_count" value=0} i_count mod 4}…
It seems to be caused by '', but why did my code execute the first div in the first div, and the contents of the second div in the second DIV later?
{if $i_count mod 4 == 0} <div>.1..<div> {else} <div>.2..<div> {/if}
{foreach from=$row item=item key=i_count} {if $i_count mod 4} <div>.2..<div> {else} <div>.1..<div> {/if}
{foreach from=$row item=item key=i_count}{if ($i_count mod 4)==0}<div>.2..<div>{else}<div>.1..<div>{/if}
This sentence can be written like this.
{if ($i_count mod 4) eq 0}