简体   繁体   English

Prestashop添加计数器并在smarty文件中用作参考时如何使用?

[英]Prestashop add a counter and use while in smarty file as the reference how?

I have my code in php for some other project is like this 我在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>

Now this gives the output like 现在这给出了输出

<div class="box active"></div>
 <div class="box"></div>
 <div class="box"></div>

In this way I have made all the posts fadein and fadeout by jQuery. 这样,我通过jQuery使所有帖子淡入淡出。

with the same reference I want to make fadein and fadeout some texts. 使用相同的参考,我想使一些文本淡入淡出。 For that I have developed module. 为此,我开发了模块。 In that I am getting all the values from database. 这样我就可以从数据库中获取所有值。 So my code for module like this 所以我的代码像这样

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

Here I have fetched the data and I have assigned the values to smarty. 在这里,我已获取数据,并将值分配给smarty。

Inside smarty my code is like this 里面聪明我的代码是这样的

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

but here I don't know how to use while and make loop counter so that I can add class active for jquery. 但是在这里,我不知道如何使用while和make循环计数器,以便可以为jquery添加活动类。 So can somone kindly tell me how to make this work? 那么somone可以告诉我如何进行这项工作吗? Any help and suggestions will be really appreciable. 任何帮助和建议都是非常可取的。 Thanks 谢谢

Your question is quite confusing, but I suppose you just need to use the @iteration property : 您的问题很令人困惑,但是我想您只需要使用@iteration属性即可

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM