【问题标题】:Smarty:How can Use Php code get the foreach's variableSmarty:如何使用php代码获取foreach的变量
【发布时间】:2013-06-19 08:08:39
【问题描述】:

我的代码:

 <!--    {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}--> 

我需要rec_cat的id,所以我使用PHP标签来获取它,但它什么都不显示?为什么?我该如何纠正?

【问题讨论】:

    标签: php foreach smarty


    【解决方案1】:

    不要在模板中使用&lt;?php标签,而是使用Smarty的{php}标签:

    http://www.smarty.net/docsv2/fr/language.function.php.tpl

    然后你得到你的变量就像这样:

    $var = $this->get_template_vars('var');
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-09-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-06-03
      • 1970-01-01
      相关资源
      最近更新 更多