Active class inside a for statement

4 posts by 2 authors in: Forums > CMS Builder
Last Post: October 1, 2014   (RSS)

Hi there - sure, you can add an active class, it just depends on how the active state is determined.

You can add something like this:

<?php foreach (getListOptions("preguntas_frecuentes", "categoria") as $value => $label):?>
    <li<?php if($value = 'something active') : ?> class="active"<?php endif; ?>> <a data-toggle="tab" href="#tab-<?php echo $value;?>"> <?php echo $label;?> </a> </li>
<?php endforeach ?> 

I'm not sure what your check should be, however. 

--------------------

Claire Ryan
interactivetools.com

Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

By Jesus - September 30, 2014

Hi Claire thanks for your answer.

I think I'm close to understand this but....

A few things....

I might have unlimited categories and something active needs to be a variable as well, because the system will have just one option as active and all others regular.

So based on this, how can or how should I set the something active value in order to work with any of my categories?

Thanks!

By claire - October 1, 2014

I can't say without knowing how you want to determine the active category. In general, the easiest thing to do would be to make the first one active and ignore the rest.

Try something like this:

<?php $count = 0; ?>
<?php foreach (getListOptions("preguntas_frecuentes", "categoria") as $value => $label):?>
    <li<?php if($count == 0) : ?> class="active"<?php endif; ?>> <a data-toggle="tab" href="#tab-<?php echo $value;?>"> <?php echo $label;?> </a> </li>
<?php $count++; ?>
<?php endforeach ?> 

--------------------

Claire Ryan
interactivetools.com

Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/