6月5日 smarty变量调节器 函数 配置文件
Posted D董小姐
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了6月5日 smarty变量调节器 函数 配置文件相关的知识,希望对你有一定的参考价值。
变量调节器:
1.capitalize[首字符大写]
main.php:
<?php include("../init.inc.php"); smarty->assign("attr","hello word");
smarty->display("main.html");
main.html:
<body> <div><{$attr|capitalize}></div> </body>
2.truncate[截取字符串]
运用同上,
truncate:30 截取字符长度30
truncate:30:"..." 第二个参数 截取30 字符,最后三个用...代替,也可以写其他
3.自己写变量调节器
把字体颜色变成绿色:
modifier.fontcolor.php://格式不能变
<?php function smarty_modifier_fontcolor($str,$color=‘green‘) { return "<span style=‘color:{$color}‘>{$str}</span>"; }
main.html:
<body> <div><{$attr|fontcolor}></div> </body>
变量调节器可以组合使用
函数;
1.<{literal}>中间内容原样输出<{/literal}>
2.html_select_date:日期下拉框
<div><{html_select_date start_year=‘1990‘ end_year=‘2020‘ momth_format=‘%m‘}></div>
3.block textarea.php:块方法,需要开始和结束,编辑器
<{textarea name=‘txt‘ toolbar=‘full‘ color=‘yellow‘ height=‘300‘}>
<{/taxtarea}>
需要js
4.自己写函数
function.typename.php
<?php function smarty_function_typename($arges) { $code = $args["code"];
if($code==0)
{
return "单选题";
}
else
{
return "多选题";
} }
main.html
<div><{typename code=$v[5]}></div>//传参数
5.块函数:开始结束各调用一次方法
main.php
<{fontstyle color=‘yellow‘}> <a>提交</a> <{/fontstyle}>
block.fontstyle.php
<?php function smarty_block_fontstyle($args,$content,$smarty,$a) {
$color = $args["color"]; if(!$a)//结束时
{
return "<span style=‘color:{$color}‘>{$content}</span>";
}
}
配置文件:
main.html
<{config_load file="style.conf" setion="one"}>//加载页面
<div style=‘color:<{#color#}>‘>配置文件</div>//用#读取color值
style.conf://配置文件
[one]//相同名区分
color=red
[two]
color=yellow
以上是关于6月5日 smarty变量调节器 函数 配置文件的主要内容,如果未能解决你的问题,请参考以下文章