Home Backend Development PHP Tutorial Smarty中的注释和截断功能介绍_php模板

Smarty中的注释和截断功能介绍_php模板

May 16, 2016 pm 08:17 PM
smarty Truncate Comment

注释

复制代码 代码如下:

{* 这是一个单行Smarty注释 来自于jb51.net,网页源代码里看不见*}


{* 这是一个多行
   Smarty注释
   并不发送到浏览器
*}

模板注释由星号包围,继而由分隔符包围,型如:{* 这是一个注释 *}。Smarty注释不会在最终模板的输出中显示,这点和不同。前者对于在模板中插入内部注释有用,因为没有人能看到。;-)

http://www.itlearner.com/code/smarty_cn/language.basic.syntax.html

截断truncate

复制代码 代码如下:

$smarty->assign('hxtitle', 'Two Sisters Reunite after Eighteen Years at Checkout Counter.');

模板为:

复制代码 代码如下:

{$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}

输出为:
复制代码 代码如下:

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.

可以不用在PHP里截取了:http://www.itlearner.com/code/smarty_cn/language.modifier.truncate.html
Statement of this Website
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

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Conveniently use PyCharm shortcut keys to implement multi-line comments Conveniently use PyCharm shortcut keys to implement multi-line comments Jan 27, 2024 am 08:02 AM

Conveniently use PyCharm shortcut keys to implement multi-line comments

How to use the TRUNCATE function in MySQL to truncate numbers to specify the number of decimal places for display How to use the TRUNCATE function in MySQL to truncate numbers to specify the number of decimal places for display Jul 26, 2023 pm 01:51 PM

How to use the TRUNCATE function in MySQL to truncate numbers to specify the number of decimal places for display

How to Optimize the Maintainability of Java Code: Experience and Advice How to Optimize the Maintainability of Java Code: Experience and Advice Nov 22, 2023 pm 05:18 PM

How to Optimize the Maintainability of Java Code: Experience and Advice

How to comment multiple lines in go language How to comment multiple lines in go language Jan 05, 2023 am 10:59 AM

How to comment multiple lines in go language

How to add notes to saved passwords on iPhone How to add notes to saved passwords on iPhone Feb 28, 2024 pm 07:41 PM

How to add notes to saved passwords on iPhone

PyCharm Annotation Operation Guide: Optimizing the Code Writing Experience PyCharm Annotation Operation Guide: Optimizing the Code Writing Experience Feb 21, 2024 pm 06:27 PM

PyCharm Annotation Operation Guide: Optimizing the Code Writing Experience

A detailed explanation of annotations in golang A detailed explanation of annotations in golang Mar 21, 2023 pm 07:38 PM

A detailed explanation of annotations in golang

The php language supports several comment styles The php language supports several comment styles Feb 15, 2022 pm 02:05 PM

The php language supports several comment styles

See all articles