Php 如何在smarty文件中添加计数器并用作参考?
我用php编写了一些其他项目的代码,如下所示Php 如何在smarty文件中添加计数器并用作参考?,php,jquery,smarty,prestashop,prestashop-1.6,Php,Jquery,Smarty,Prestashop,Prestashop 1.6,我用php编写了一些其他项目的代码,如下所示 <div class="post-wrap"> $i = 0; while ( have_posts() ) $i++; if($i==1) { $class= 'active'; } else { $class= ''; } <div class="box '.$class.'"></div> endwhile; </div> public fun
<div class="post-wrap">
$i = 0;
while ( have_posts() )
$i++;
if($i==1) {
$class= 'active';
}
else {
$class= '';
}
<div class="box '.$class.'"></div>
endwhile;
</div>
public function hookfooter($params) {
$popup_styles = "SELECT * FROM "._DB_PREFIX_."database ORDER BY `id` DESC LIMIT 1";
$popup_styles_settings = Db::getInstance()->ExecuteS($popup_styles);
$this->context->smarty->assign('PopupStyles',$popup_styles_settings);
return $this->display(__FILE__, 'views/templates/front/footer-display.tpl');
}
{foreach from=$sliderValues item=row}
<div class="box">name</div>
<div class="box">name2</div>
<div class="box">name3</div>
{/foreach}
在这里,我获取了数据,并将值分配给smarty
在smarty里面,我的代码是这样的
<div class="post-wrap">
$i = 0;
while ( have_posts() )
$i++;
if($i==1) {
$class= 'active';
}
else {
$class= '';
}
<div class="box '.$class.'"></div>
endwhile;
</div>
public function hookfooter($params) {
$popup_styles = "SELECT * FROM "._DB_PREFIX_."database ORDER BY `id` DESC LIMIT 1";
$popup_styles_settings = Db::getInstance()->ExecuteS($popup_styles);
$this->context->smarty->assign('PopupStyles',$popup_styles_settings);
return $this->display(__FILE__, 'views/templates/front/footer-display.tpl');
}
{foreach from=$sliderValues item=row}
<div class="box">name</div>
<div class="box">name2</div>
<div class="box">name3</div>
{/foreach}
{foreach from=$sliderValues item=row}
名称
姓名2
名字3
{/foreach}
但在这里,我不知道如何使用while和make循环计数器,以便为jquery添加活动类。
那么有人能告诉我怎么做吗?任何帮助和建议都是非常值得的。谢谢您的问题很让人困惑,但我想您只需要使用:
$sliderValues
的内容是什么?