简体   繁体   English

laravel在菜单栏中添加带有其他页面链接的下拉菜单

[英]laravel add a drop down in menu bar with links to other pages

I am new to laravel and the blade templet setup. 我是Laravel和Blade Templet设置的新手。 I am working on setting up an art website to show paintings and so on. 我正在建立一个艺术网站来展示绘画等。 Right now I got a basic index.blade.php, however, I want to change one the links into a dropdown to show other options. 现在我有了一个基本的index.blade.php,但是,我想将其中一个链接更改为一个下拉列表,以显示其他选项。 I seem not to be able to grasp how to get it to work. 我似乎无法掌握如何使其工作。

This is how my basic setup looks like. 这是我的基本设置的样子。

<div id="navbar" class="navbar-collapse collapse">
            <ul class="nav navbar-nav navbar-right" style="color: black">
                <li><a
                            @if( $page == 'about')
                            class="activePage"
                            @else
                            class="nonActivePage"
                            @endif
                            href="./about">About the Artist</a></li>
                <li><a
                            @if( $page == 'products')
                            class="activePage"
                            @else
                            class="nonActivePage"
                            @endif
                            href="./product">Products</a></li>
                <li><a
                            @if( $page == 'order')
                            class="activePage"
                            @else
                            class="nonActivePage"
                            @endif
                            href="./order">Order</a></li>
                <li><a
                            @if( $page == 'contact')
                            class="activePage"
                            @else
                            class="nonActivePage"
                            @endif
                            href="#" onclick="contact();">Contact</a></li>

            </ul>
        </div>

However, under Products, I want to add Watercolor, Oil and Acrylic paintings. 但是,在“产品”下,我想添加水彩画,油画和丙烯酸画。

This is what I thought may work but I seem not to grasp the whole blade structure at this point. 我认为这可能会起作用,但此时我似乎还不掌握整个刀片的结构。

<div id="navbar" class="navbar-collapse collapse">
            <ul class="nav navbar-nav navbar-right" style="color: black">
                <li><a
                            @if( $page == 'about')
                            class="activePage"
                            @else
                            class="nonActivePage"
                            @endif
                            href="./about">About the Artist</a></li>
                 <li class="dropdown">
                    @if( $page == 'product')
                        <a class="dropdown-toggle activePage" data-toggle="dropdown" href="#">
                            Product</a>
                        <ul>
                            <li><a href="./about">Watercolor paintings</a></li>
                            <li><a href="#">This</a>Oil Paintings</li>
                            <li><a href="#">That</a>Acrylic Paintings</li>
                        </ul>
                    @else
                        <a class="nonActivePage" href="#">
                            Product</a>
                    @endif
                </li>
                <li><a
                            @if( $page == 'order')
                            class="activePage"
                            @else
                            class="nonActivePage"
                            @endif
                            href="./order">Order</a></li>
                <li><a
                            @if( $page == 'contact')
                            class="activePage"
                            @else
                            class="nonActivePage"
                            @endif
                            href="#" onclick="contact();">Contact</a></li>

            </ul>
        </div>

It just is not showing the ul dropdowns at all. 它只是根本不显示ul下拉列表。 Any pointers are greatly appreciated. 任何指针,不胜感激。

first of all, try to give a name to every single route in your router (web.php): 首先,尝试为路由器(web.php)中的每个路由命名。

Route::any('/about', 'someConntroller@someaction')->name('about');

then use route method in your views. 然后在您的视图中使用route方法。 here is a simple example: 这是一个简单的示例:

<li>
    <a {{ $page == 'about' ? 'class="activePage"' : 'class="nonActivePage"' }}
        href="{{ route('about') }}">
            About the Artist
    </a>
</li>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM