Home > Backend Development > PHP Tutorial > How smarty implements i

How smarty implements i

WBOY
Release: 2016-06-27 13:18:09
Original
1389 people have browsed it

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 ++ ;                    }%>
Copy after login



This is what I wrote, but ERROR
                   {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}
Copy after login


How do I write it? Did I write i wrong?


Reply to discussion (solution)

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}
Copy after login

I haven’t tested it. If it doesn’t work, just use $i_count 1 Use `` to cause




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} 
Copy after login

{foreach from=$row item=item key=i_count}                                            {if $i_count mod 4}                                                             <div>.2..<div>                                                    {else}                                                              <div>.1..<div>                           {/if}
Copy after login

{foreach from=$row item=item key=i_count}{if ($i_count mod 4)==0}<div>.2..<div>{else}<div>.1..<div>{/if}
Copy after login

This sentence can be written like this.

{if ($i_count mod 4) eq 0}
Copy after login

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template