Wednesday, April 17, 2013

Yii Framework - Twiiter Bootstrap TbMenu in Navbar options

To get the image to work just embed an image in the brand name like so:


'brand'=>'<img src="path_to_img.jpg"/>"

Add extra parameters to TbMenu

'itemOptions' not 'htmlOptions' when an item has htmlOptions. So to add an id use:

array('label'=>'First Link', 'url'=>"#", 'itemOptions'=>array('id' => 'xyz'))
 

Define $this->activeMenu in your main Controller and 

set value to $this->activeMenu from anywhere.

 
<?php 
if($this->activeMenu == null) {
    $this->activeMenu = "null";
}
$this->widget('bootstrap.widgets.TbNavbar',array(
    'items'=>array(
        array(
            'class'=>'bootstrap.widgets.TbMenu',
            'items'=>array(
                array(
                    'label'=>'Home', 
                    'url'=>array('/site/index'), 
                    'visible'=>Yii::app()->user->isGuest
                ),
                array(
                    'label'=>'About', 
                    'url'=>array('/site/page', 'view'=>'about'), 
                    'visible'=>Yii::app()->user->isGuest
                ),
                array(
                    'label' => 'Contact group', 
                    'url' => array('/group/index'),
                    'itemOptions' => array(
                        "class" => "group_nav"
                    ),
                    "active" => $this->activeMenu == "group_nav"
                ),
                array(
                    'label' => 'Contact list', 
                    'url' => array('/contact/index'),
                    'itemOptions' => array(
                        "class" => "contact_nav"
                    ),
                    "active" => $this->activeMenu == "contact_nav"
                ),
                array(
                    'label'=>'Logout ('.Yii::app()->user->name.')', 
                    'url'=>array('/site/logout'), 
                    'visible'=> !Yii::app()->user->isGuest
                )
            )
        )
    )
)); 
?> 

No comments:

Post a Comment