Convert HTML Megamenu to Yii CMenu zii Widget -


i started working yii, , having trouble converting html megamenu yii. html this:

<div class="nav-wrapper">     <div class="container">         <ul class="some_class">             <li class="active"><a href="#">parent 1</a>                 <div class="megamenu">                     <div class="row">                         <a href="#" class="overview">child 1</a>                     </div>                     <div class="row">                         <div class="col1">                             <ul>                                 <li><a href="#">child 3</a></li>                                 <li><a href="#">child 4</a></li>                             </ul>                         </div>                                   </div>                 </div>             </li>          </ul>      </div> 

adapting cmenu widget proving more difficult thouht...especially e starter me. can come classes , lists, how put divs within cmenu widget?

thanks

you should create own widget. creating widget not harder creating controllers.

start simple, see how plays. lets try something, quick example, not handle recursion, fine:

class mymenu extends cwidget {     public $items = [];     public function init()     {        // possibli items     }      public function run()     {         $this->render('menu', ['items' => $this->items]);     } } 

in views/menu.php:

<div class="nav-wrapper">     <div class="container">         <ul class="some_class">               <?php foreach($items $item):?>             <li class="active"><a href="#"><?=$item['title'];?></a>                 <div class="megamenu">                      <div class="row">                         <a href="#" class="overview"><?= $item['overview'];?></a>                     </div>                     <div class="row">                         <div class="col1">                             <ul>                                          <?php foreach($item['items'] $row):?>                                 <li><a href="#"><?= $row['title'];?></a></li>                                           <?php endforeach;?>                             </ul>                         </div>                     </div>                 </div>             </li>                 <?php endforeach;?>          </ul>      </div> </div> 

then use in ccontorller view

<?php $this->widget('path.to.mymenu', [     'items' => [         [             'title' => 'foo',             'overview' => 'some overview',             'items' => [                 [                     'title' => 'bar'                 ],                 [                     'title' => 'baz'                 ]             ]         ]     ] ]); ?> 

disclaimer: not tested, show idea, might work or not.


Comments

Popular posts from this blog

java - Intellij Synchronizing output directories .. -

git - Initial Commit: "fatal: could not create leading directories of ..." -