Php template engine smarty variable type

Source: Internet
Author: User
There are multiple types of php template engine smarty variables. different types of variables are differentiated by their prefix. If you want to output a variable, you can enclose it with a delimiter. there are multiple types of variables in the php template engine smarty, and different types of variables are differentiated by their prefix.
If you want to output a variable, you can enclose it with a delimiter, for example:
{$ Name}
{$ Contacts [row]. Phone}

Type 1: The variables allocated from PHP and The assign function in the template must be preceded by the "$" symbol. (more common, the instance can refer to the above code) Type 2: variables read from the configuration file or smarty variables ($ smarty. config), which is included in "#" when displayed. code instance:
Foo. conf configuration file
 
PageTitle = "cn-web.com demo"
BodyBgColor = "# eeeeee"
TableBorderSize = "3"
TableBgColor = "# bbbbbb"
RowBgColor? "# Cccccc"
 
Index. tpl File (call method 1)
 
{Config_load file = "foo. conf "}

{# PageTitle #}







   
FirstLastAddress



 
Index. tpl: (alternate syntax) call method 2
 
{Config_load file = "foo. conf "}

{$ Smarty. config. pageTitle}







   
FirstLastAddress



 
 
OUTPUT: (the OUTPUT results of the two examples are the same)
 

This is mine







   
FirstLastAddress


Configuration file variables are used only when they are loaded.
 
Type 3: reserved variables
{$ Smarty. variable} reserved variables can be used to access some special template variables.
For example:
Request variables [page Request variable]
{$ Smarty. now}
{$ Smarty. const}
{$ Smarty. capture}
{$ Smarty. config}
{$ Smarty. section}, {$ smarty. foreach}
{$ Smarty. template}

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.