Not able to add css class to link in menu widget yii2

I am trying to set css class to link in Yii2 Menu Widget. I have added below code as items, but after page rendering , no class attribute added in link.

[‘label’=>$item->title,‘url’=>$item->url,‘linkOptions’=>[‘class’=>‘stest’,‘target’=>’_blank’]];

Options also tried but it sets css class to li tag, not a tag.

Please provide your input where I am going wrong.

There is no linkOptions parameter. Use modified linkTemplate parameter to add class to link tag.

http://www.yiiframework.com/doc-2.0/yii-widgets-menu.html#$linkTemplate-detail

@Bizley Thanks for your reply,

I have checked linkTemplate option, But it is common for all links. But What if I want to add css class to specific links in menu? How can I add css class for specific links?

Have you read the description given for this parameter?

Yes I have checked description and I understood this If I am not wrong. I have applied this then it adds class to both links. But what if I want to add only for Home link.




    'items' => [

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

	['label' => 'About', 'url' => ['site/about']],

    ],

   'linkTemplate' => '<a href="{url}" class="mylink"><span>{label}</span></a>',



Please correct me if I am going wrong. Thank you




'items' => [

    ['label' => 'Home', 'url' => ['site/index'], 'template' => '<a href="{url}" class="mylink"><span>{label}</span></a>'],

    ['label' => 'About', 'url' => ['site/about']],

],



Oh That’s Great. It is working now. I have added this into my knowledge

Thank you much Bizley.