Active class inside a for statement

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

By Jesus - September 29, 2014 - edited: September 29, 2014

Hi, I'm wondering if there's an option where I can get a class for an active link for a statement like this.

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

I need to have an active tab inside my for statement... that means just one of my categories will have the active class, like this:

<li class="active"> <a data-toggle="tab" href="#tab-<?php echo $value;?>"> <?php echo $label;?> </a> </li>

The final html code should look like this:

<li> <a data-toggle="tab" href="#tab-Generales"> Generales </a> </li>
<li class="active"> <a data-toggle="tab" href="#tab-Servicios"> Servicios </a> </li>
<li> <a data-toggle="tab" href="#tab-Nutrición"> Nutrición </a> </li>

Thanks!

By claire - September 30, 2014

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!