1

i'm working with yii2 and uikit. i'm trying to build a navbar with the menu widget and i have this:

<nav class='uk-navbar'>            
        <?php
        echo Menu::widget([
            'activateItems' => true,
            'activateParents' => true,
            'activeCssClass' => 'uk-active',
            'encodeLabels' => false,
            'items' => [
                ['label' => 'Inicio', 'url' => ['site/index']],
                ['label' => 'Juridico', 'url' => ['juridico/index']],
                ['label' => 'Pagos', 'url' => ['pagos/index']],
                ['label' => 'Universidades', 'url' => ['universidades/index']],
                ['label' => 'Usuarios', 'url' => ['usuarios/index']],
                ['label' => 'Planes', 'options' => ['class' => 'uk-parent', 'data' => 'uk-dropdown'], 'url' => ['#'], 'items' => [
                        ['label' => 'Planes Juridico', 'url' => ['#']],
                        ['label' => 'Planes Universidades', 'url' => ['#']],
                    ]],
                ['label' => 'Login', 'url' => ['site/login'], 'visible' => Yii::$app->user->isGuest],
            ],
            'submenuTemplate' => '<div class="uk-dropdown uk-dropdown-navbar"><ul class="uk-nav uk-nav-navbar">{items}</ul></div>',
            'options' => [ 'class' => 'uk-navbar-nav'],
        ]);
        ?>     
    </nav>

all i'm missing is this attribute but i don't know how to set it 'data-uk-dropdown'

i need this result in order to the dropdown to work:

<nav class="uk-navbar">
        <ul class="uk-navbar-nav">
            <li class="uk-active"><a href="">Active</a></li>
            <li><a href="">Item</a></li>
            <li class="uk-parent" data-uk-dropdown>
                <a href="">Parent</a>
                <div class="uk-dropdown uk-dropdown-navbar">
                    <ul class="uk-nav uk-nav-navbar">
                        <li><a href="#">Item</a></li>
                        <li><a href="#">Another item</a></li>
                        <li class="uk-nav-header">Header</li>
                        <li><a href="#">Item</a></li>
                        <li><a href="#">Another item</a></li>
                        <li class="uk-nav-divider"></li>
                        <li><a href="#">Separated item</a></li>
                    </ul>
                </div>
            </li>
        </ul>
    </nav>

Thanks in advance.

2 Answers 2

1

have you try to add in the 'options' like below?

<?php
    echo Menu::widget([
        'activateItems' => true,
        'activateParents' => true,
        'activeCssClass' => 'uk-active',
        'encodeLabels' => false,
        'items' => [
            ['label' => 'Inicio', 'url' => ['site/index']],
            ['label' => 'Juridico', 'url' => ['juridico/index']],
            ['label' => 'Pagos', 'url' => ['pagos/index']],
            ['label' => 'Universidades', 'url' => ['universidades/index']],
            ['label' => 'Usuarios', 'url' => ['usuarios/index']],
            ['label' => 'Planes', 'options' => ['class' => 'uk-parent', 'data' => 'uk-dropdown'], 'url' => ['#'], 'items' => [
                    ['label' => 'Planes Juridico', 'url' => ['#']],
                    ['label' => 'Planes Universidades', 'url' => ['#']],
                ]],
            ['label' => 'Login', 'url' => ['site/login'], 'visible' => Yii::$app->user->isGuest],
        ],
        'submenuTemplate' => '<div class="uk-dropdown uk-dropdown-navbar">    <ul class="uk-nav uk-nav-navbar">{items}</ul></div>',
        'options' => [ 
'class' => 'uk-navbar-nav',
'data-uk-dropdown' => ''
],
    ]);
    ?>   
Sign up to request clarification or add additional context in comments.

1 Comment

yes, i've tried that but it does'nt work that way. is not about an attribute and value type of. is the full name that i've posted.
0

I think this is how you can add data attributes same method would work in other Yii2 places. So you specify the key 'data' and then add an array of just the attribute names (without prefixing them with 'data'. You can read more about it here.

NavBar::begin([
    'options' => [
        'id' => 'main-nav-bar',
        'class' => 'navbar-inverse',
        'data' => ['my-attribute' => 'myValue'] // This line specifically.
    ],
    'innerContainerOptions' => ['class' => 'container-fluid']
]);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.