3. Methods
l assign : Assign variables to templates
l assignByRef: assign variables to templates (pass by reference)
The difference betweenDisplay and fetch:
4. Filter
Filters are used to filter data
1. Types of filters:
1) Prefilters Prefilters
2) Post filters Postfilters
3) Output Filters
The above three filters are divided into three types according to different triggering times
2. Workflow
tpl source file => Prefilter => Compile tpl file => Postfilter => Save to disk => Execute the compiled php file => Output Filters (=> If there is smart cache, the contents of Output Filters Will be cached) => Result output.
3. Register filter
In Smarty, filters must be registered before they can be used
In 2.6, register filters
l Prefilters
$smarty->register_prefilter(“func”);
l Postfilters
$smarty->register_postfilter(“func”);
l Output Filters
$smarty->register_outputfilter(“func”);
Registering different filters calls different methods.
In 3.0, register 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 when compiled for the first time, or will be executed again after the template is changed
The output filter will be executed every time