How smarty implements I ++

Source: Internet
Author: User
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}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.