0

I've created Yii Bootstrap TbMenu.How can I dynamically add the active class?

$this->widget('bootstrap.widgets.TbMenu',
    array(
        'type' => 'list',
        'items' => array(
            array(
                'label' => 'Home',
                'url' => '#',
                'itemOptions' => array('class' => 'active')
            ),
            array('label' => 'Library', 'url' => '#'),
            array('label' => 'Applications', 'url' => '#'),
        )
    )
);
Arash K
  • 13
  • 1
  • 8

1 Answers1

0

Maybe with inline if?

$this->widget('bootstrap.widgets.TbMenu',
array(
    'type' => 'list',
    'items' => array(
        array(
            'label' => 'Home',
            'url' => '#',
            'itemOptions' => (($isActive) ? array('class' => 'active') : array())
        ),
        array('label' => 'Library', 'url' => '#'),
        array('label' => 'Applications', 'url' => '#'),
    )
)

);

Frildoren
  • 243
  • 3
  • 9