收藏的smarty总觉
{html_table loop=$data cols=4 hdir="right" vdir="down" trailpad="填补空格" tr_attr="bgcolor='red'"??
table_attr='border="2"'}
{mailto address="me@domain.com" text="联系我们" cc="to@sdf.com,to2@sd.com" bcc="an@song.com" subject="我毕业了。"
extra='x=3 y=4}>
<{textformat wrap=1}>大????#$????家?????? 好?????? 啊。<{/textformat}>textformat 用于格式化文本. 该函数主要清理空格和特殊字符,
没有缓存的:<{$smarty.now}>
一、模板中调用php文件中函数
php文件中的方法:
function insert_get_time(){//insert 函数默认是不缓存的。并且这个属性不能修改
return date("Y-m-d H:m:s");
}
模板中调用:<{insert name="get_time"}>
还可以传递参数如下:
php端:
function insert_getBanner($array){
print_r($array);//$lid是个数组
return $array['lid'];
}
模板中调用:<{insert name="getBanner" lid='dd' sid='aa'}>
二、模板中定义变量
{assign var="UserName" value="大师兄"}在模板内部定义一个变量UserName值为“大师兄”
三、动态生成radio,checkedbox,options
php文件中的radio方法:
$tpl->assign('cust_radios', array(
1001 => 'Joe Schmoe',
1002 => 'Jack Smith',
1003 => 'Jane Johnson',
1004 => 'Charlie Brown'));
$tpl->assign('customer_id', 1001);
模板中调用:
<{html_radios name="id" options=$cust_radios checked=$customer_id separator="<br />"}>
php文件中的checkedbox方法:
$tpl->assign('cust_checkboxes', array(
1000 => 'Joe Schmoe',
1001 => 'Jack Smith',
1002 => 'Jane Johnson',
1003 => 'Charlie Brown'));
$tpl->assign('customer_id', 1001);
模板中调用:
<{html_checkboxes name="id" options=$cust_checkboxes checked=$customer_id separator="<br />"}>
php文件中的options方法:
$tpl->assign('cust_options', array(
1001 => 'Joe Schmoe',
1002 => 'Jack Smith',
1003 => 'Jane Johnson',
1004 => 'Charlie Brown'));
$tpl->assign('customer_id', 1001);
模板中调用:
<select name=customer_id>
<{html_options options=$cust_options selected=$customer_id}>
</select>
四、用{$smarty.capture.foo}调用capture中的内容
<{capture name="foo"}>呵呵。<{/capture}>
<{$smarty.capture.foo}>
五、计数器
<{counter start=0 skip=2 print=false assign=aa}>??计数器
<{$aa}>??????
<{counter}><{$aa}>
<{counter}><{$aa}>
六、Cycle用来循环显示一组数值
{section name=rows loop=$data}
<tr bgcolor="{cycle values="#eeeeee,#d0d0d0"}">
<td>{$data[rows]}</td>
</tr>
{/section}
七、得到文件的内空,并赋给变量
<{fetch file="http://www.test.com/aa.html" assign="test"}> <{$test}>用来取得文件内容,并输出文件内容.
八、语法
if:
<{if $name !== ""}>
<b><{$name}></b>
<{/if}>
foreach:
<{foreach key=key item=value from=$news}><!--foreach循环数组 -->
键值:<{$key}>
内容:<{$value.id}>
<{$value.title}>
<{$value.data}><br>
<{/foreach}>
section:
<{section name=list loop=$news}>
<font color="#0000FF"><{$news
- ?
- ?
- .data}>></font><br>
<{/section}>
在模板中还可以执行php语句,真强。不过这点很好用的。
<{php}>
global $tpl;
global $db;
$typeArr = $tpl -> get_template_vars("value");
$IndustryBig = $typeArr[IndustryBig];
$db->query("SELECT Name FROM `cy_class_industry` where ID='$IndustryBig'");
$row = $db->fetchRow();
echo $row['Name'];
<{/php}>
数学算法和日期的格式化显示
<{math equation="(x-y)/60" x=$logArr[num].logoutTime y=$logArr[num].loginTime format="%.1f"}> <font color="red">分钟</font>
.title}></font><font color="gray"><<{$news .id}></font> <font color="#FF0000"><{$news