Smarty intercepts strings and calls methods in php. foreach loop 1. smarty truncate string & nbsp; code & nbsp; & lt; {$ content | truncate: 30: & quot ;... & q smarty intercepts the string, calls the method in php, and runs the foreach loop.
1. smarty truncated string
Code in html <{$ content | truncate: 30: "..."}>
Cut the $ content string by 30 characters, and use "..." to replace the subsequent content.
2. smarty calls methods in php
Code in html<{$ Content | sub}>
Pass $ content as a variable to the method sub in php (the php page here is the php page on the display html page)
Code in php
Function sub ($ con ){
Return "123 ";
}
?>
If you want to pass multiple parameters to the methods on the php page
The codes <{$ content | sub: "aa": "bb"}> aa and bb in html are the second and third parameters.
Pass $ content as a variable to the method sub in php (the php page here is the php page on the display html page)
Code in php
Function sub ($ con, $ aa, $ bb ){
Return "123 ";
}
?>
3. foreach loop
<{Foreach item = arr from = $ row}> $ row is an array passed from the php page.
<{$ Arr. name}>
<{/Foreach}>