smarty 3.16 函数的使用
点击 1817 创建时间 2011-12-08 11:48:54
<p> 在smarty中使用修改器很是不方便,有时有的函数用不上,实际上smarty是可以使用php的系统函数的。</p> <p> </p> <p> <?php</p> <p> //index.php</p> <p> require('lib/smarty/Smarty.class.php');<br /> <br /> $smarty = new Smarty;<br /> <br /> <br /> $smarty->template_dir = dirname( FILE ) . "/templates";<br /> $smarty->force_compile = true;<br /> //$smarty->debugging = true;<br /> $smarty->caching = true;<br /> $smarty->cache_lifetime = 120;<br /> <br /> $arr = array(<br /> array("name" => "yqr" , "age" => 27 ),<br /> array("name" => "zsf" , "age" => 23 )<br /> );<br /> $smarty->assign("rows" , $arr );<br /> $smarty->display('index.html');</p> <p> ?></p> <p> 下面,在index.html中使用count()、substr()、trim()、floatval()等php系统函数。</p> <p> <strong>index.html</strong></p> <p> smarty test<br /><br /> <br /> count:{count($rows)} <br /><br /> <b>print_r</b><br /> {print_r($rows)}<br /> <br /><br /> <br /> {foreach from=$rows item="r"}<br /> {substr(trim($r.name),1,2)} , {floatval($r.age)*3.4} <br /><br /> {/foreach}</p>
上一篇: amfphp2.0 入门demo
下一篇: Rong Framework将为模板引擎加入修改器