smarty变量调节器

smarty变量调节器是用来改变显示的值,不改变变量的值
系统自带调节器:
首字符大写:<div><{$test|capitalize}></div>
连接字符串:<div><{$money|cat:"$"}></div>
                  :<div><{$zifu|count_characters}></div>
格式化日期:<div><{$riqi|date_format:"%D %T"}></div>
设置默认值:<div><{$moren|default:"hello"}></div>
<div><{$suojin|indent:10}></div>
正则--替换:<div><{$zhengze|regex_replace:"/d/":"qq"}></div>
字符串替换:<div><{$zhengze|replace:"l":"8"}></div>
字符串截取:<div><{$jiequ|truncate:8:"..."}></div>
 
可以自定义调节器:
具体步骤:
在目录文件夹plugins中添加插件:取名为:modifier_mingzi.php
内容是:
<?php
function smarty_modifier_mingzi($str,$color="red",$size="16"){
        $str = "<span style='color:{$color}; font-size:{$size}px'>{$str}</span>";
        return $str;
}
<div><{$ceshi|yangshi:"blue":20}></div>
<div><{$jiequ|substr:8:"***"}></div>
<div><{$sex|sexname}></div>
也可以连接数据库操作
<?php
function smarty_modifier_nationname($nation){
    $db = new MySQLi("localhost","root","123","mydb");
    $sql = "select name from nation where code='{$nation}'";
    $result = $db->query($sql);
    $attr = $result->fetch_row();
    return $attr[0];
}
<div><{$nation|nationname}></div>
原文地址:https://www.cnblogs.com/naqiang/p/5707795.html