【问题标题】:Prestashop add a counter and use while in smarty file as the reference how?Prestashop 在 smarty 文件中添加一个计数器并使用作为参考如何?
【发布时间】:2014-06-02 17:55:54
【问题描述】:

我的代码在 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>

现在这给出了类似

的输出
<div class="box active"></div>
 <div class="box"></div>
 <div class="box"></div>

通过这种方式,我将所有的帖子都通过jQuery淡化和淡出。

我想使用相同的参考来淡入和淡出一些文本。为此,我开发了模块。我正在从数据库中获取所有值。所以我的模块代码是这样的

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');
 }

在这里我已经获取了数据并将值分配给 smarty。

在 smarty 里面我的代码是这样的

 {foreach from=$sliderValues item=row}
  <div class="box">name</div>
  <div class="box">name2</div>
  <div class="box">name3</div>
 {/foreach}

但在这里我不知道如何使用 while 和制作循环计数器,以便我可以为 jquery 添加活动类。 那么有人可以告诉我如何进行这项工作吗?任何帮助和建议都将是非常可观的。谢谢

【问题讨论】:

  • $sliderValues的内容是什么?

标签: php jquery smarty prestashop prestashop-1.6


【解决方案1】:

你的问题很混乱,但我想你只需要使用@iteration property:

{foreach $sliderValues as $row}
{if $row@iteration == 1}
... do something ...
{/if}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-11-09
    • 2015-12-21
    • 2016-09-20
    • 2023-03-25
    • 2015-07-13
    • 2023-04-08
    相关资源
    最近更新 更多