Smarty is a template engine written in PHP. It separates logical code and external content, providing an easy-to-manage and use method. This article mainly introduces the annotation and truncation functions in Smarty. These two functions are not commonly used in Smarty, but they are very practical. Friends who need them can refer to them.
Comments
Copy code The code is as follows:
{* This is a single-line Smarty comment From jb51.net, invisible in the web page source code*}
{* This is a multi-line
Smarty comment
and is not sent to the browser
*}
Template comments are surrounded by asterisks, followed by delimiters, such as: {* This is a comment*}. Smarty comments will not be displayed in the output of the final template, unlike this. The former is useful for inserting internal comments in templates where no one else can see them. ;-)
http://www.itlearner.com/code/smarty_cn/language.basic.syntax.html
truncate
Copy code The code is as follows:
$smarty->assign('hxtitle', 'Two Sisters Reunite after Eighteen Years at Checkout Counter.');
The template is:
Copy code The code is as follows:
{$hxtitle}
{$hxtitle|truncate}
{ $hxtitle|truncate:30}
{$hxtitle|truncate:30:""}
{$hxtitle|truncate:30:"---"}
{$hxtitle|truncate:30:" ":true}
{$hxtitle|truncate:30:"...":true}
{$hxtitle|truncate:30:'..':true:true}
Output Copy the code for:
##The code is as follows:Two Sisters Reunite after Eighteen Years at Checkout Counter.
Two Sisters Reunite after Eighteen Years at Checkout Counter .Two Sisters Reunite after...
Two Sisters Reunite after
Two Sisters Reunite after---
Two Sisters Reunite after Eigh
Two Sisters Reunite after E...
Two Sisters Re..ckout Counter.
You don’t need to intercept it in PHP: http://www.itlearner.com/code/smarty_cn/language.modifier.truncate.html
Related Recommended:
How to nest loops in smartyHow to use the variable regulator in Smarty templateHow to generate Smarty Simple form elementsThe above is the detailed content of Detailed explanation of annotation and truncation functions in Smarty. For more information, please follow other related articles on the PHP Chinese website!