• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

Smarty中的注释和截断功能详解

php 搞代码 4年前 (2022-01-22) 20次浏览 已收录 0个评论

Smarty是一个使用PHP写出来的模板引擎。它分离了逻辑代码和外在!本文来源gaodai#ma#com搞*!代#%^码网5

搞gaodaima代码

的内容,提供了一种易于管理和使用的方法。这篇文章主要介绍了Smarty中的注释和截断功能介绍,这两个功能都是Smarty中不太常用的功能,但非常实用,需要的朋友可以参考下。

注释

{* 这是一个单行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.');<br />

模板为:

{$hxtitle}<br />{$hxtitle|truncate}<br />{$hxtitle|truncate:30}<br />{$hxtitle|truncate:30:""}<br />{$hxtitle|truncate:30:"---"}<br />{$hxtitle|truncate:30:"":true}<br />{$hxtitle|truncate:30:"...":true}<br />{$hxtitle|truncate:30:'..':true:true}

输出为:

Two Sisters Reunite after Eighteen Years at Checkout Counter.<br />Two Sisters Reunite after Eighteen Years at Checkout Counter.<br />Two Sisters Reunite after...<br />Two Sisters Reunite after<br />Two Sisters Reunite after---<br />Two Sisters Reunite after Eigh<br />Two Sisters Reunite after E...<br />Two Sisters Re..ckout Counter.

可以不用在PHP里截取了:http://www.itlearner.com/code/smarty_cn/language.modifier.truncate.html

相关推荐:

smarty如何嵌套循环

Smarty模板如何使用变量调节器

Smarty如何生成简单的表单元素

以上就是Smarty中的注释和截断功能详解的详细内容,更多请关注搞代码gaodaima其它相关文章!


搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:Smarty中的注释和截断功能详解

喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址