Smarty intercepts a string, invokes a method in PHP, and a foreach loop
1.smarty Intercept string
The code in HTML <{$content |truncate:30: "..."}>
Truncate the $content string by 30 characters, followed by "..." To replace
2.smarty calling Methods in PHP
the code in HTML <{$content |sub}>
The $content character channeling is passed as a variable to the method sub in PHP (The PHP page here is the PHP page of the display HTML page)
The code in PHP
function sub ($con) {
return "123";
}
?>
If you want to pass multiple arguments to a method in a PHP page
code in HTML <{$content |sub: "AA": "BB"}> AA and BB are the second and third parameters
The $content character channeling is passed as a variable to the method sub in PHP (The PHP page here is the PHP page of the display HTML page)
The code in PHP
function sub ($con, $AA, $BB) {
return "123";
}
?>
3.foreach Cycle
<{foreach item=arr from= $row}> $row is an array passed from the PHP page.
<{$arr .name}>
<{/foreach}>