This article mainly introduces the annotation and truncation functions in Smarty. These two functions are not very commonly used in Smarty, but they are very practical. For more information, see
Note
The code is as follows:
{* This is a single line of Smarty annotation from jb51.net, which is invisible in the source code of the webpage *}
{* This is a multiline
Smarty comments
Not sent to the browser
*}
Template comments are surrounded by asterisks and then surrounded by delimiters. type: {* This is a comment *}. The Smarty annotation is not displayed in the output of the final template. The former is useful for inserting internal comments in the template, because no one can see it .; -)
Http://www.itlearner.com/code/smarty_cn/language.basic.syntax.html
Truncate
The code is as follows:
$ Smarty-> assign ('hxtitle', 'Two Sisters Reunite after Eighteen Years at Checkout Counter .');
Template:
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}
Output:
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 have to truncate it in PHP: http://www.itlearner.com/code/smarty_cn/language.modifier.truncate.html