Clevercode found that calling PHP built-in functions in Smarty can be implemented by | | There are no spaces before and after. If it is an array, count needs to be added @.
1 parameters at a time:
{' param1 ' |functionname}}
For example
{{$tmpStr |strlen}}
2 parameters at a time:
{' param1 ' |functionname: ' Param2 '}} {$tmpStr |substr: ' 1 '}
Multiple parameter times:
{' param1 ' |functionname: ' param2 ': ' Param3 ' ...}} {{$tmpStr |substr: ' 1 ': ' 2 '}} {' A ' |str_replace: ' A ': $tmpStr}}
1 Marty to determine whether it is empty
The following code PHP is assigned to TMPSTR is empty or not assigned; then output in Smarty is 0. This is the built-in function called PHP strlen
PHP Code:
$smarty->assign (' tmpstr ', '); Smarty Code: {{if $tmpStr |strlen > 0}} 1{{else}}
2 Marty to find the array length
The array length is evaluated using PHP's built-in functions Is_array and count, such as code output 5
PHP Code:
$smarty->assign (' Tmparr ', Array (1,2,3,4,5));
Smarty Code:
{{if $tmpArr |is_array && $tmpArr | @count > 0}} {{$TMPARR | @count}} {{Else}} 0{{/IF}}
3 Marty String substitution
The following code is to replace B in tmpstr with C
$smarty->assign (' tmpstr ', ' ABB '); {' B ' |str_replace: ' C ': $tmpStr}}
Output:
Acc
4 Marty Intercept Field
$smarty->assign (' tmpstr ', ' ABB '); {{$tmpStr |substr: ' 1 '}}
Output:
Bb
{{$tmpStr |substr: ' 1 ': ' 1 '}}
Output:
B