Home  >  Article  >  Backend Development  >  Detailed explanation of annotation and truncation functions in Smarty

Detailed explanation of annotation and truncation functions in Smarty

php中世界最好的语言
php中世界最好的语言Original
2018-03-06 11:24:391546browse

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 smarty

How to use the variable regulator in Smarty template

How to generate Smarty Simple form elements

The 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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn