Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Yii2 How can i add a class to Label of a Menu items

Tags:

yii2

How can I add a CSS class on a Label (item)

Example:

['label'=>'Home', 'url'=>['site/home']]

This does not work

['label'=>'Home', 'class'=>'list-group-item', 'url'=>['site/index']],

like image 236
kouwen Avatar asked Sep 14 '14 10:09

kouwen


1 Answers

Just open source of Nav widget:

/**
     * @var array list of items in the nav widget. Each array element represents a single
     * menu item which can be either a string or an array with the following structure:
     *
     * - label: string, required, the nav item label.
     * - url: optional, the item's URL. Defaults to "#".
     * - visible: boolean, optional, whether this menu item is visible. Defaults to true.
     * - linkOptions: array, optional, the HTML attributes of the item's link.
     * - options: array, optional, the HTML attributes of the item container (LI).
     * - active: boolean, optional, whether the item should be on active state or not.
     * - items: array|string, optional, the configuration array for creating a [[Dropdown]] widget,
     *   or a string representing the dropdown menu. Note that Bootstrap does not support sub-dropdown menus.
     **/

so if you want to add class to li item, use

['label'=>'Home', 'url'=>['site/index'],'options'=>['class'=>'list-group-item']]

if you want to add class to link

[
  'label'=>'Home', 
  'url'=>['site/index'],
  'options'=> ['class'=>'list-group-item'],
  'linkOptions'=>['class'=>'item-a-class'],
]
like image 106
user1852788 Avatar answered Sep 24 '22 18:09

user1852788