Introduction to annotation and truncation functions in Smarty _ php template

Source: Internet
Author: User
Tags php template
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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.