: This article mainly introduces the php-Smarty-7 (24), for PHP tutorials interested in students can refer to it. III. Methods
L assign: assign variables to the template
L assignByRef: assign variables to the template (pass by reference)
L append: append the template variable to an array.
L appendByRef: append Template variables to an array (passed by reference)
L clearAllAssign
Clear all assigned variables
L sort ache
Clear Cache
L configLoad load the configuration file
In smarty, there are two ways to load the configuration file:
1) in the template {config_load file = '.... '}
2) in the program $ smarty-> configLoad ($ file [, $ section])
L clearConfig
Clear all configuration file variables
L display
Read, replace, and output
L fetch
Read, replace, and return
L templateExists: determines whether the template exists
If you try to load a template that does not exist, an error will be reported. you should judge before it is displayed.
Differences between assign and assignByRef:
Difference between Display and fetch:
IV. filter
A filter is used to filter data.
1. filter types:
1) prefilter Prefilters
2) Postfilters
3) Output filter Output Filters
Based on the trigger time, the above three filters are divided
2. workflow
Tpl source file => Prefilter => compile tpl file => Postfilter => save to disk => run the compiled PHP file => Output Filters (=> if there is a smarty cache, output Filters content will be cached) => result Output.
3. Register a filter
In Smarty, the filter must be registered before use
In 2.6, register the filter
L Prefilters
$ Smarty-> register_prefilter ("func ");
L Postfilters
$ Smarty-> register_postfilter ("func ");
L Output Filters
$ Smarty-> register_outputfilter ("func ");
Register different filters to call different methods.
3.0, register the filter
$ Smarty-> registerFilter ($ type, $ callback );
$ Type: filter type
Value range:
Pre: Pre-filter
Post: Post filter
Output: Output filter
$ Callback: filter function
4. Code:
The pre-filter and post-filter will be executed during the first compilation, or the template will be executed again after the template changes.
The output filter is executed every time.
The above introduces the php-Smarty-7 (24), including the content of the aspect, hope to be interested in PHP Tutorial friends help.