在Laravel Bade View中的“父级和子菜单”上设置类

时间:2018-08-16 04:00:03

标签: laravel laravel-5 laravel-blade

我想根据当前页面在Laravel徽章中的父菜单m-menu__item--open上设置<li>类,在子菜单项m-menu__item--active上设置<li>类。以下是从bade模板中提取的HTML

<li class="m-menu__item m-menu__item--open" aria-haspopup="true" m-menu-submenu-toggle="hover">
    <a href="javascript:;" class="m-menu__link m-menu__toggle">
        <i class="m-menu__link-icon flaticon-layers"></i>
        <span class="m-menu__link-text">FAQ</span>
        <i class="m-menu__ver-arrow la la-angle-right"></i>
    </a>
    <div class="m-menu__submenu " m-hidden-height="840">
        <span class="m-menu__arrow"></span>
        <ul class="m-menu__subnav">
            <li class="m-menu__item  m-menu__item--active" aria-haspopup="true">
                <a href="{{ url('/') }}/admin/faq/list/1" class="m-menu__link ">
                    <i class="m-menu__link-bullet m-menu__link-bullet--dot">
                        <span></span>
                    </i>
                    <span class="m-menu__link-text">English</span>
                </a>
            </li>
            <li class="m-menu__item  m-menu__item" aria-haspopup="true">
                <a href="{{ url('/') }}/admin/faq/list/2" class="m-menu__link ">
                    <i class="m-menu__link-bullet m-menu__link-bullet--dot">
                        <span></span>
                    </i>
                    <span class="m-menu__link-text">Korean</span>
                </a>
            </li>
            <li class="m-menu__item  m-menu__item" aria-haspopup="true">
                <a href="{{ url('/') }}/admin/faq/list/3" class="m-menu__link ">
                    <i class="m-menu__link-bullet m-menu__link-bullet--dot">
                        <span></span>
                    </i>
                    <span class="m-menu__link-text">Chinese</span>
                </a>
            </li>
        </ul>
    </div>
</li>

1 个答案:

答案 0 :(得分:0)

据我了解,您想通过当前网址更改菜单类。

laravel在Request类中具有is()方法。您可能要使用它。

class="{{Request::is('category/products') ? 'm-menu__item--active' : 'm-menu__item--open'}}"

如果您当前的网址为base-url/category/products,那么您将获得'm-menu__item-active'类