Smarty template, smarty

Source: Internet
Author: User

Smarty template, smarty

Although the smarty template is not very easy to use, we still need to know some of the basics and methods to help us understand the principles of phpcms and learn the tp framework.

The following describes the usage of built-in functions. The first is foreach.

1 foreach is a block function, that is, there are beginning and end, <{foreach}> <{/foreach}>

For example, in the main folder, I created a file named test. php, whose content is

<? Phpinclude (".. /init. inc. php "); $ arr = array (" n001 "," Han "), array (" n002 "," Hui "), array (" n003 ", "Miao") $ smarty-> assign ("arr", $ arr); $ smarty-> display(test.html); // html file created in the template folder

In test.html, it is represented:

<select>    <{foreach $arr as $v}>    <option><{$v[1]}></option>    <{/foreach}></select>


<Select> <{foreach $ arr as $ k = >$ v}> <option ><{$ k }><{$ v [1] }></option> here is different, the results are different <{/foreach}> </select>

Is indexed:

2 is a small plug-in about keywords, that is, when the keyword is marked as: modifier. key. php

<?phpfunction smarty_modifier_key($str,$key) {    return str_replace($key,"<mark>$key</mark>",$str);}
$ Smarty-> assign; furniture hot and sour home China Branch Shengli Street is annoying to see the other side is considering the Chinese style has reduced the aircraft Scola aircraft ");
<{$ Title | key: "China "}


3. textarea tag: a built-in plug-in smarty

<{textarea color="red" toolbar="full"}><{/textarea}>


4. Use its built-in plug-in to select and represent the year, month, and day.

<{html_select_date month_format="%m"}>


5. Color plug-ins

<{color name="color"}>


6. Time Selection plug-in

<{date name="riqi"}>


I think these plug-ins may be used later. I just sorted them out to facilitate searching for them.


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: 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.