码迷,mamicode.com
首页 > 其他好文 > 详细

6月5日 smarty变量调节器 函数 配置文件

时间:2016-06-06 21:59:17      阅读:154      评论:0      收藏:0      [点我收藏+]

标签:

 

变量调节器:

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变量调节器 函数 配置文件

标签:

原文地址:http://www.cnblogs.com/dongqiaozhi/p/5564999.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!