Smarty Function---plug-in
1) built-in function sysplugins does not allow modification
2) Custom Function plugins can be modified
1. Capture captures a piece of content, but does not output
Grammar:
{Capture name= ' var '}
Content
{/capture}
Name: Save the content to the specified variable
{$smarty. Capture.var}
In the template, a large amount of content that needs to be output over and over again can be considered using capture captures.
2. config_load Load configuration file
{config_load file= "file" section= "section"}
File: Profile Name
Section: Which configuration sections to refer to optional parameters
Reference syntax:
{#var #}
{$smarty. Config.var}
3. Foreach,foreachelse for traversing arrays
Grammar:
{foreach from= array key= key name= name item= content}
{Foreachelse} when the array to be traversed does not have any elements, execute the statement after Foreachelse
{/foreach}
From: Array to traverse
Item: The key value to traverse to
Key: The name of the keys that are traversed
Name: Name the foreach statement
foreach Built-in variables
$smarty. Foreach.name.index: Index starting from 0
$smarty. Foreach.name.iteration: Index starting from 1
$smarty. Foreach.name.first: This value is true when the loop is executed for the first time
$smarty. Foreach.name.last: This value is true when the loop is last executed
$smarty. Foreach.name.total: Total number of loops
4. Include referencing another template file
{include file= "file" assign= "var" [var ...]}
File: Template files to be introduced
Assign: Saves the result, but does not output this time
[var ...] : Optional parameters, parameter for template file
5. include_php contains a PHP file
{include_php file= "file" assign= "var" once= "True|false"}
File: PHP files to be introduced
Assign: Save output, but not output at this time
Once: Contains only one time true: false: No
This function is available in smarty2.6, but the function is removed in 3.0, and if you want to use this function, you can refer to the SmartyBC.class.php class file
6, insert in the template, execute a PHP function
Grammar:
{Insert Name= "func" [var ...]}
Name: called PHP function name
[var ...] : Specify parameter optional parameters when calling function
Insert and include_php are the same. Are all functions in the 2.6, and in 3.0, this function is placed in the SmartyBC.class.php file.
Note: The name of the PHP function referenced by inser must be prefixed with Insert_
7. If ElseIf else
{if}
{ElseIf}
{Else}
{/if}
8, Ldelim, Rdelim the escape character of {} in template
{Ldelim}
{Rdelim}
9, literal literal mark in the middle of the content will not be resolved by smarty
{literal}
......
{/literal}
10. PHP can write PHP code in a pair of PHP tags
{PHP}
......
{/php}
Php-smarty-4 (21)