在smarty中,遇到这样的html代码。**
{section name=listAll loop=$scope}
(input id="a1" name="from" / >
(input id="b1" name="from" / >
(input id="c1" name="from" / >
{/section}
{section name=listAll loop=$scope}
(input id="a2" name="from" / >
(input id="b2" name="from" / >
(input id="c2" name="from" / >
{/section}
{section name=listAll loop=$scope}
(input id="a3" name="from" / >
(input id="b3" name="from" / >
(input id="c3" name="from" / >
{/section}
我可以将其转移到如下函数:
function RenderControl($i)
{
return '
{section name=listAll loop=$scope}
(input id="a$i" name="from" / >
(input id="b$i" name="from" / >
(input id="c$i" name="from" / >
{/section}
} ';
然后在 tpl 文件中调用它,例如:
{RenderControl i=1}
{RenderControl i=2}
{RenderControl i=3}
为什么以下内容不适用于 smarty tpl?$smarty->register_function('RenderHtml','RenderHtml'); 函数 RenderHtml($params){ 提取($params); // $html= ' {include file="tke-pre_bid_scopeworkModules/Section1_Factory_to_Price_Optional_Configuration.tpl"} ' ; 返回 $html; }
{RenderHtml 数=12}