Jump to content

Use while and counter in smarty template ?


Recommended Posts

Hi,

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

Link to comment
Share on other sites

×
×
  • Create New...