通常,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的数值。