Built-in functions
Built-in functions cannot be modified without authorization.
Capture
The capture function is used to collect the data output from the template to a variable instead of outputting the data to the page. for example, any data between {capture name = "foo"} and {/capture} is received in the variable {$ Foo} specified by the function name attribute, or {$ smarty. capture. foo. If the function does not have a name attribute, "default" will be used. Each {capture} must correspond to {/capture}, and the capture function cannot be nested.
Config_load
Reference configuration file
File is required. It indicates the name of the configuration file to be included, section indicates the name of the part to be loaded, and scope of the variable to be processed by scope. It must be local, parent, or global.
Local means that the variable will be loaded in this template.
Parent means that the variables will be loaded in this template and the parent template.
Global means that the variable will be applied to all templates. The default value is local. Whether the variable is visible in the upper-level template. The default value is no. If the scope attribute already exists, this value is ignored.
Foreach, foreachelse
A foreach loop is a selective section loop. It is used to traverse associated arrays. the syntax of foreach is much simpler than section, but as a compromise, it can only be used for simple arrays.
The required parameters of foreach are from and item. the from variable indicates the name of the array to be cyclic, the item indicates the variable name of the current element, the key indicates the variable name of the current keyword, and the name indicates the foreach loop name that accesses the foreach attribute. Loops can be nested with each other. The names of nested loops must be independent. foreachelse is executed when the from variable has no value.
Include
Used to reference other templates.
The file attribute is required to indicate the name of the referenced template, and assign indicates the output variable to be allocated to the include file. You can define any local variable by property name = "property value.
Include_php
It is used to introduce PHP scripts in the template. File is required to indicate the path of the PHP script. Once, determine whether to load the PHP script once if it is referenced multiple times in the template. The default value is true.
Insert
Used to include functions in the PHP script. Name is required to indicate the name of the inserted script. Note that if the name is name, the included function is insert_name (), therefore, all functions to be inserted must have the prefix insert _. If the assign attribute is used, the insert output will be allocated to the template variables and will not be displayed. Script indicates the path of the script to be referenced. ThisProgramThe generated content will not be cached and re-executed each time the page is called. This applies to interaction areas such as advertising, voting, and query results.
The following describes how to transmit parameters to insert in smarty:
The following describes how to pass parameters through the insert method in smarty:
Smarty template:
{Insert name = "getpara" p1 = "php" p2 = "Zixue "}
PHPCode:
Function insert_getpara ($ ARR)
{
Return $ arr ["p1"]. "". $ arr ["p2"];
}
Output: PhP Zixue
When using the insert method, there must be "insert _" before the function name in the Code. Otherwise, an error will occur, except for the template rules.
Among them, P1 and P2 are the two parameter names to be passed, which can have multiple, any, as long as the corresponding inside and outside the line. $ arr indicates that the array is also casually written.
If, elseif, else
The IF statement is similar to the condition in PHP, but each word must be separated by a space. There are also some new condition statements, which are listed as follows: equal EQ, unequal NE and NEQ, greater than GT, less than, greater than or equal to GTE and GE, less than or equal to LTE and le, not non. Mod modulo. Is [not] Div by can be divisible by a certain number, is [not] Even is an even number, $ A is [not] even by $ B ($ A/$ B) % 2 = 0, is [not] whether odd is odd, $ A is not odd by $ B ($ A/$ B) % 2! = 0
PHP
PHP markup allows the template to directly use the PHP language.
Section, sectionelse
Section is used to display array data cyclically. Name and loop are required parameters. Name indicates that the nested name. Section can be nested, but the names must be different. Loop indicates the number of cycles. sectionelse outputs when the loop parameter is null. Start is used to specify the pointer at the beginning of the loop. If the value is negative, the pointer starting from the end of the array is calculated. The default value is 0. step indicates the number of steps in the cycle. If it is negative, the reverse loop is used. The default value is 1. max sets the maximum number of cycles. show determines whether to display section.
Section also has its own Variable Processing Section attribute, which is displayed using {$ smarty. Section. sectionname. varname.
Index
Index is used to display the pointer of the current loop, starting from 0.
Index_prev
The pointer used to display the previous loop, starting from-1.
Index_next
The pointer used to display the next loop.
Iteration
Displays the number of times of the current loop, starting from 1.
First
If the current loop is the first loop, the value is true.
Last
If the current loop is the last loop, the value is true.
Rownum
Same as iteration.
Loop
Display the pointer of the last loop, which can be used anywhere in the center of the section or after the section.
Show
Show determines whether to display section.
Total
Displays the total number of cycles, which can be used anywhere in the center of a section or after a section.
Strip
Remove unnecessary Spaces