简体   繁体   中英

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

<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.

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.

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. So can somone kindly tell me how to make this work? 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 :

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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