如何把下面这段C#代码翻译成smarty下的代码?
<% int i_count = 0; foreach (GridViewRow row in this.GridView1.Rows) { if (i_count%4 == 0) {%> .1..<% } else {%> .2..<% } i_count ++ ; }%> 我写的是这样,但是ERROR
{assign var="i_count"} {foreach from=$row item=item} {if $i_count mod 4} .2.. {else} .1.. {/if} {$i_count + 1 } {/foreach} 请问如何写?是我i++写错了吗
回复讨论(解决方案)
你为什么要这样写? smarty foreach 里面可以获取当前key 的 {foreach from=$var key=k item=v}
这个k就是了 呵呵
{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} 没测试, 不行的话就把$i_count+1用``引起来
Plain Text code?1234567891011121314{assign var="i_count" value=0} {foreach from=$row item=item} {if $i_count mod 4} ……
貌似要''引起来,但是为什么我的代码就第一次执行第一个div里的,后面都执行第二个div里的内容?
{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} 这句可以这么写.
{if ($i_count mod 4) eq 0}