杨庆荣的博客

工作之余接单:公司产品展示网站建设、电商网站建设、小程序、app开发。+86 13714715608

smarty 3.16 函数的使用

点击 1817    创建时间 2011-12-08 11:48:54

<p> 在smarty中使用修改器很是不方便,有时有的函数用不上,实际上smarty是可以使用php的系统函数的。</p> <p>  </p> <p> &lt;?php</p> <p> //index.php</p> <p> require('lib/smarty/Smarty.class.php');<br /> <br /> $smarty = new Smarty;<br /> <br /> <br /> $smarty-&gt;template_dir = dirname( FILE ) . "/templates";<br /> $smarty-&gt;force_compile = true;<br /> //$smarty-&gt;debugging = true;<br /> $smarty-&gt;caching = true;<br /> $smarty-&gt;cache_lifetime = 120;<br /> <br /> $arr = array(<br />     array("name" =&gt; "yqr" , "age" =&gt; 27 ),<br />     array("name" =&gt; "zsf" , "age" =&gt; 23 )<br /> );<br /> $smarty-&gt;assign("rows" , $arr );<br /> $smarty-&gt;display('index.html');</p> <p> ?&gt;</p> <p> 下面,在index.html中使用count()、substr()、trim()、floatval()等php系统函数。</p> <p> <strong>index.html</strong></p> <p> smarty test&lt;br /&gt;<br /> <br /> count:{count($rows)} &lt;br /&gt;<br /> &lt;b&gt;print_r&lt;/b&gt;<br /> {print_r($rows)}<br /> &lt;br /&gt;<br /> <br /> {foreach from=$rows item="r"}<br />   {substr(trim($r.name),1,2)}  ,  {floatval($r.age)*3.4} &lt;br /&gt;<br /> {/foreach}</p>

上一篇: amfphp2.0 入门demo
下一篇: Rong Framework将为模板引擎加入修改器