技术 · 2013 年 12 月 12 日

smarty 输出数字格式化(整数、小数、时间格式等)

{capture name=banner}{*注释掉中间显示内容*}
{include file=”banner.tpl”}
{/capture}
{include file=”banner.tpl” title=”Smarty学习”}
{$smarty.get.page}

{$smarty.post.page}

{$smarty.cookies.name}

{$smarty.server.SERVER_NAME}

{$smarty.env.PATH}

{$smarty.session.id}

{$smarty.request.username}

{$smarty.now|date_format:’%Y-%m-%d %H:%M:%S’}

{$smarty.const.PAGETITLE}{*常量*}

Hello {$name}{*变量*}

{html_select_date display_days=yes}

{$member.fax}

{$member.phone.home}

{$tempmember.member}

{$tempmember.phone.home}{*多维数组*}

{#error_message#}{*配置文件属性*}

{$name|lower}{*smarty字符串函数*}

{$name|upper}{*smarty字符串函数*}

{‘now’|date_format:’%Y-%m-%d’}{*smarty日期函数*}

{$title|truncate:11:”…”}{*截断字符串超长加…*}

{mailto|lower address=”mailto:linux@admin.com%22%7D%7B*mailto邮件*}

mailto:%7B$tempmember%7C@count}{*数据的总和*}

{$english_word|capitalize}{*首字母大写*}

{$english_word|capitalize:true}{*每个单词的首字母大写*}

{$title|count_characters:true}{*字符串的长度加true字符空格,不加true不计算空格*}

{$title|cat:’字符串后加入字符’}{*拼接字符串*}

{$title|count_words}{*计算字符数量*}

{$title2|default:”dsgadsgds”};{*如果变量不存在就输出默认值*}

{$english_word|escape:html}{*将字符串中的HTML转换为HTML编码方式*}

{$english_word|escape:htmlall}{*将字符串中的HTML转换为HTML编码方式*}

{$english_word|escape:url}{*将字符串中的HTML转换为URL编码方式*}

{$english_word|escape:quotes}{*将字符串中的HTML转换为HTML编码方式*}

{$title|indent:100}{*缩进指定宽度*}

{$title|regex_replace:”/要/”:”爱”}{*正则表达式替换字符*}

{$title|replace:”要”:”爱”}{*Replace替换字符*}

{$english_word|spacify:”||”}{*分隔字符串*}

{$money|string_format:”%.2f”}{*格式化数字为Float数*}

{$money|string_format:”%d”}{*格式化数字为INT数*}

{$english_word|strip:” “}{*替换空格*}

{$english_word|strip_tags:false}{*替换标签*}

{$english_word|truncate:10:”…”}{*截取指定长度字符,默认截取80字符长度*}

{$english_word|wordwrap:10}{*多长后字符串换行,默认换行长度为80*}

{$english_word|upper|spacify|truncate:30:”…”}{*Smarty支持多个函数的组合,此组合为字符串先大写然后分隔然后截取指定长度*}

{foreach name=outer item=contact from=$contacts}{*foreach循环数组*}
{foreach key=key item=item from=$contact}
{$key}:{$item}

{/foreach}
{/foreach}
{foreach name=outer item=contact2 from=$contacts2}
{foreach key=key item=item from=$contact2}
{$key}:{$item}

{/foreach}
{/foreach}
{include_php file=”function.php”}{*包含指定的PHP文件*}
{insert name=”top” lid=”toplid” sid=”topsid”}{*调用insert_top PHP函数,函数参数为lid和sid的值*}
{if 1 eq 1}{*条件判断语句*}
1=1
{elseif 1 ne 1}
1!=1
{elseif 1 gt 1}
1>1
{elseif 1 lt 1}
1<1 {elseif 1 gte 1} 1>=1
{elseif 1 lte 1}
1<=1 {elseif not 1 eq 1} not 1=1 {elseif (1 mod 1) eq 1} 1%1=1
{else}
你的人品真不好
{/if}
{ldelim}function insert_top {rdelim} is insert_top {*输出中括号*}
{literal}{*加入一段HTML,脚本代码等*}

{/literal}
{*包含一段PHP语句*}
{php}
echo “php代码运行”;
{/php}
{section name=member loop=$contacts3 show=true}{*while循环 show是否SHOW section中的循环内容*}
{if $smarty.section.member.first}
first
{/if}
{if $smarty.section.member.last}
last
{/if}
current loop rownum:{$smarty.section.member.rownum}

current loop iteration:{$smarty.section.member.iteration}

index:{$smarty.section.member.index} index_prev:{$contacts3[member.index_prev]} index_next:{$contacts3[member.index_next]} index:{$contacts3[member.index]} member:{$contacts3[member]}
{section name=memberchild loop=$contacts4[member] max=2}
memberchild:{$contacts4[member][memberchild]}
{/section}
total:{$smarty.section.member.total}{*数据长度或总记录数*}
{/section}