MacGyer/yii2-materializecss

NavBar isn't rendering NavSideItems using the basic main file provided in the src

Closed this issue · 2 comments

 NavBar::begin([
        'brandLabel' => 'My Company',
        'brandUrl' => Yii::$app->homeUrl,
        'options' => ['class' => 'light-blue lighten-1',],
        'fixed' => true,
        'wrapperOptions' => [
            'class' => 'container'
        ],
    ]);

    $menuItems = [
        ['label' => 'Home', 'url' => ['/site/index'], 'linkOptions' => ['class'=>'']],
        ['label' => 'About', 'url' => ['/site/about']],
        ['label' => 'Contact', 'url' => ['/site/contact']],
    ];
    if (Yii::$app->user->isGuest) {
        //$menuItems[] = ['label' => 'Signup', 'url' => ['/site/signup']];
        $menuItems[] = ['label' => 'Login', 'url' => ['/site/login']];
    } else {
        $menuItems[] = '<li>'
                . Html::beginForm(['/site/logout'], 'post')
                . Html::submitButton(
                        'Logout (' . Yii::$app->user->identity->username . ')', ['class' => 'btn btn-flat']
                )
                . Html::endForm()
                . '</li>';
    }

    echo Nav::widget([
        'options' => ['class' => 'right hide-on-med-and-down '],
        'items' => $menuItems,
    ]);

    

    NavBar::end();

NavSide isn't creating the links

I've changed to make it work on NavBar widget

/**
* Renders the side nav toggle button.
*
* @return string the button markup.
* @throws \Exception
*/
protected function renderSidenavToggleButton() {
// legacy Button::widget($this->sidenavToggleButtonOptions);
//01 - test if isn't empty
$name = $target = $class = '';
if (isset($this->sidenavToggleButtonOptions)):
$info = $this->sidenavToggleButtonOptions;
$name = $info['icon']['name'];
$target = $info['options']['data-target'];
$class = $info['options']['class']['trigger'];
endif;

    return "<a href='#' class='{$class}' data-target='{$target}' > <i class='material-icons'>{$name}</i></a>";
}

Did you study the NavBar class?
Whatever you do, the side nav has special properties to fill and get rendered

https://github.com/MacGyer/yii2-materializecss/blob/master/src/widgets/navigation/NavBar.php#L147