Implementation code for similar for loop functions in smarty templates

WBOY
Release: 2016-07-25 08:58:32
Original
905 people have browsed it
  1. {section name=total loop=100}
  2. {$smarty.section.total.index+1} //Current index
  3. {$smarty.section.total.iteration} //Used to display loops Times
  4. {/section}
Copy code

You can also do this:

  1. {assign var=i value=0}
  2. {section name=total loop=100}
  3. {assign var=i value=$i+1} {$i} //Assign using assign method
  4. {/section}
Copy code

Output results: 1 2 3 4 5 ... ... 100

In addition, let’s introduce how to use php functions in smarty.

In the smarty template, if you use the php function, a function with only one parameter, such as removing blank trim, can be written like this: example 1:

  1. <{$colname|trim}>
Copy code

So what should I write if I use a function with three parameters like iconv? If written: Example 2:

  1. <{$colname|iconv:'utf-8':'gbk'}>
Copy the code

You will find an error message displayed as soon as you execute it. Starting from the application function usage on the smarty template page, taking Example 1 as an example, the $Row->colname in front of trim is actually the first parameter of trim, and is concatenated with the symbol | in the middle; If you want to use a function with three parameters like iconv, you should write: Example 3:

  1. <{'utf-8'|iconv:'gbk':$colname}>
Copy the code

That is, the first parameter of the function | function: the second parameter: the second parameter three parameters. In Example 3, the value of colname will be converted from utf-8 format to gbk.



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