How To Add Html Cmenu In Yii

Hi Everybody,

Hope you are all doing well. I have been trying to implement CMenu in Yii template. I am using,




    $this->widget('zii.widgets.CMenu', array(

                'items'=>$this->menu,

                'htmlOptions'=>array('class'=>'collapse','id'=>'component-nav'),

    ));



And I want to dislpay my HTML output as




    <li class=""><a href="icon.html"><i class="icon-angle-right"></i> List Registration </a></li>



But I can not insert this section: &lt;i class=&quot;icon-angle-right&quot;&gt;&lt;/i&gt; beside the label i.e. "List Registration". Is there any way to insert this &lt;i class=&quot;icon-angle-right&quot;&gt;&lt;/i&gt; html part beside every label of item.

Please help me someone.

Thanks in advance


array('label'=>'Contact', 'icon'=>'icon-angle-right','url'=>array('/site/contact')),

It’s html code will be something like this


<li><a href="/site/contact"><i class="icon-angle-right"></i> View</a></li>

Hi Prat,

Thanks to prompt reply. I have applied but does not show output as required. And also, I want to add this HTML code for all items of the menu not individual.

Regards,

Shimul

For all items you could do like array() and you will get the html code for all items of menu. I suppose you want display icons for each menu item? Have you included some icon pack? because I don’t think CMenu includes any icon pack.

Thanks Prat, I caught your advise and got the solution in two ways. However, according to my question, my solution is




$this->menu = array_map(function($item){

            $item["label"] = '<i class="icon-angle-right"></i>' .' '. $item["label"];

            $item["encodeLabel"] = false;

            return $item;

        }, $this->menu);


        $this->widget('zii.widgets.CMenu', array(

            'items'=>$this->menu,

            'htmlOptions'=>array('class'=>'collapse','id'=>'component-nav'),

            'encodeLabel' => false,

        ));



You can also extend CMenu class and override renderMenuItem() method.