标签:
前台显示:
<{config_load file=‘test.conf‘}><!--加载配置文件--><!--注释哪条配置文件在哪条前面加分号;--> </head> <body bgcolor="<{$smarty.config.bgcolor}>">//加载配置文件可以用#号也可以用此方式
注释的两种方式:<{**}>和<!--注释html代码-->
比如:
<{* <div style="width:100px; height:100px; background-color:#C90"><{$aa}></div> *}> 区别:<{**}>在网页源代码中不显示,<!---->在源代码中显示; <!--模板里面变量定义:$+变量名,$a; 双引号解析变量:"$a"; 模板界面可以进行运算:<div><{$a+$b}></div>;--> <!--忽略smarty解析 <{literal}> <{$aa}>//把不想要解析的内容扔进来,原样输出; <{/literal}> --> <!--输出数组元素: <div><{$shuzu.one}></div> <div><{$shuzu["one"]}></div>--> <!--输出对象的成员变量 <div><{$duixiang->host}></div> --> <!--配置文件--> <!--分块 <{config_load file=‘test.conf‘ section="one"}> <div style="width:200px; height:100px; background-color:<{#bg#}>; size:<{#size#}>">11</div> <{config_load file=‘test.conf‘ section="two"}> <div style="width:200px; height:100px; background-color:<{#bg#}>; size:<{#size#}>">22</div> --> <!--<{$smarty.now}>当前时间戳 <{$smarty.const.ROOT}> 返回常量 <{$smarty.const.CSS_PATH}> <{$smarty.config.bgcolor}>加载配置文件的另一种方式 <{$smarty.ldelim}><{$smarty.rdelim}>返回左右分隔符 -->
条件语句
<!--<{if $a lt 10}> 方法 <{elseif $a gt 20}> 加发奖金 <{else}> 带灯 <{/if}>-->
循环语句 <{foreach $shuzu as $k=>$v}> <div><{$v@index}>--<{$v@iteration}><{$v@first}><{$v@last}>-<{$k}>---><{$v}></div> <{/foreach}> <table width="100%" cellpadding="0" cellspacing="0"> <tr> <td>代号</td> <td>名称</td> <td>操作</td> </tr> <{foreach $shuzu1 as $v}> <{if $v@first }> <tr bgcolor="#FF6600"> <td><{$v.code}></td> <td><{$v.name}></td> <td>操作</td> </tr> <{elseif $v@last }> <tr bgcolor="#FF6600"> <td><{$v.code}></td> <td><{$v.name}></td> <td>操作</td> </tr> <{elseif $v@iteration%2 == 0}> <tr bgcolor="#CCCCCC"> <td><{$v.code}></td> <td><{$v.name}></td> <td>操作</td> </tr> <{else}> <tr> <td><{$v.code}></td> <td><{$v.name}></td> <td>操作</td> </tr> <{/if}> <{/foreach}> </table> </body>
后台变量值
<?php include("../init.inc.php"); include("../DBDA.php"); $attr=array("one"=>1,"two"=>2,"three"=>3); $dx=new DBDA(); $att = array( array("code"=>"n001","name"=>"汉族"), array("code"=>"n002","name"=>"回族"), array("code"=>"n003","name"=>"维吾尔族"), array("code"=>"n004","name"=>"苗族"), array("code"=>"n005","name"=>"藏族"), array("code"=>"n006","name"=>"朝鲜族"), ); $smarty->assign("aa","hello"); $smarty->assign("shuzu",$attr); $smarty->assign("duixiang",$dx); $smarty->assign("a","40"); $smarty->assign("shuzu1",$att); $smarty->display("test.html");
标签:
原文地址:http://www.cnblogs.com/jinshui/p/5700304.html