ecshop模版中使用assign賦值-更便捷的獲取數據


通常,ecshop中獲取數據的時候,都是相應的php文件中自定義變量,然后賦值assign('var',$var),再從模版中取值,這是比較規范的步驟;

不過,如果你想快速的獲取自己自定義的數據,其實在模版里面就可以賦值,接着再取值,類似如下:

               <ul class="floor-words">
                            <?php
                            $ii = 0;
                            $GLOBALS['smarty']->assign('child_cat_hot',get_hot_cat_tree($GLOBALS['smarty']->_var['goods_cat']['id'], 3));
                            ?>
                            <!--{foreach from=$child_cat_hot item=cat name=name1}-->
                            <!--{foreach from=$cat.child item=cat_child name=name}-->
                            <?php
                            $ii = $ii + 1;
                            $GLOBALS['smarty']->assign('ii', $ii);
                            ?>
                            <!--{if  $ii < 9 }-->
                            <li>
                                <a href="{$cat_child.url}" title="{$cat_child.name|escape:html}">
                                    {$cat_child.name|escape:html}
                                </a>
                            </li>
                            <!-- {/if} -->
                            <!--{/foreach}-->
                            <!--{/foreach}-->
                        </ul>

直接在模版中:$GLOBALS['smarty']->assign進行賦值操作,然后再取值,比一般的模版開發過程要簡單很多。

 

小技巧:

$GLOBALS['smarty']->_var 獲取的是代碼中使用assign賦值的變量,比如在index.php中 $smarty->assign('a',1),那么在模版文件中index.dwt使用$GLOBALS['smarty']->_var['a']獲取該變量$a的數值。

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM