[英]Smarty:How can Use Php code get the foreach's variable
My Code: 我的代码:
<!-- {foreach from=$goods_cat.cat_id item=rec_cat name=f1}-->
<?php
**echo $rec_cat[id]; // get nothing, why?**
$smarty->assign('goods_cat_' . $rec_cat[id], assign_cat_goods($rec_cat[id], 4));
$smarty ->assign('cat_goods_nf' , 'goods_cat_' . $rec_cat[id]);
?>
<!--{foreach from=$cat_goods_nf item=goods}-->
{$goods.url}
<!--{/foreach}-->
<!--{/foreach}-->
I need the id of rec_cat ,so I use PHP Tags to get it,but Its display nothing? 我需要rec_cat的ID,所以我使用PHP标记来获取它,但是它什么也不显示? why ?How can I correct it? 为什么?我该如何纠正?
Don't use <?php
tag inside a template, but instead use {php}
tag of Smarty : 不要在模板内使用<?php
标签,而应使用Smarty的{php}
标签:
http://www.smarty.net/docsv2/fr/language.function.php.tpl http://www.smarty.net/docsv2/fr/language.function.php.tpl
Then you get your variables just like so : 然后,您将获得变量,如下所示:
$var = $this->get_template_vars('var');
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.