drvlf9739 2018-10-29 11:46
浏览 47

在不同的刀片中使用侧边栏

I'm a newbie in laravel and actually I have to write the sidebar in every blade of the application to make it work, but I'd like using a different sidebar depending on the section of the site where I am. So this is what I'm trying to do:

EDIT 1

layouts/main.blade.php

<div class="wrapper">
   <div class="sidebar" data-color="brown" data-active-color="danger">
      <div class="logo">
         <!-- Content -->
      </div>
      <!-- Sidebar -->
      @if(request()->is("{{ url('/')}}/{operator}"))
         @include('operator.sidebar')
      @else
         @include('stduser.sidebar')
      @endif
      <!-- End sidebar -->
   </div>

   <div class="main-panel">
      <!-- Navbar -->
      <nav></nav>
      <!-- End navbar -->

      <!-- Main content section -->
      @yield('main-panel')
      <!-- End main content section -->

      <!-- Footer -->
      <footer></footer>
      <!-- End footer -->
   </div>
</div>

stduser/dashboard.blade.php

@extends('layouts.main')

@section('main-panel')
   <!-- Main panel contents -->
@endsection

@section('extrajs')
   <!-- script contents -->
@endsection

stduser/sidebar.blade.php

<div class="sidebar-wrapper">
  <div class="user btn-rotate">
     <div class="photo">
        <i class="fa fa-user-circle-o fa-2x" aria-hidden="true" style="color:#fff"></i>
     </div>
     <div class="info">
        <a href="{{ url('/user') }}/profile">
           <span>
              {{ Auth::user()->name }}
           </span>
        </a>
        <div class="clearfix"></div>
     </div>
  </div>

  <ul class="nav">
     <li class="active btn-rotate">
        <a href="{{ url('/') }}">
           <i class="nc-icon nc-bank"></i>
           <p>Companies</p>
        </a>
     </li>
  </ul>
</div>

operator/sidebar.blade.php

<div class="sidebar-wrapper">
  <div class="user btn-rotate">
     <div class="photo">
        <i class="fa fa-user-circle-o fa-2x" aria-hidden="true" style="color:#fff"></i>
     </div>
     <div class="info">
        <a href="{{ url('/user') }}/profile">
           <span>
              {{ Auth::user()->name }}
           </span>
        </a>
        <div class="clearfix"></div>
     </div>
  </div>

  <ul class="nav">
     <li class="active btn-rotate">
        <a href="{{ url('/') }}/{{ $operator->id }}/about">
           <i class="fa fa-tachometer" aria-hidden="true"></i>
           <p>DashBoard</p>
        </a>
     </li>
     <li class="btn-rotate">
        <a href="{{ url('/')}}/{{ $operator->id}}/suppliers">
           <i class="fa fa-link" aria-hidden="true"></i>
           <p>Suppliers</p>
        </a>
     </li>
     <li class="btn-rotate">
        <a href="{{ url('/')}}/{{ $operator->id}}/products">
           <i class="fa fa-product-hunt" aria-hidden="true"></i>
           <p>Products</p>
        </a>
     </li>
  </ul>
</div>

This is how my views are structured:

enter image description here

Is there a way to make it work?

  • 写回答

2条回答 默认 最新

  • douyi2107 2018-10-29 12:02
    关注

    you can include the blade file like so @include('layouts/sidebar_' . $sidebarName) and if you want to avoid errors when include doesnt exist you can use @includeIf('view.name', ['some' => 'data'])

    So you have just the include statement and the sidebar content only once

    评论

报告相同问题?

悬赏问题

  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?
  • ¥15 matlab(相关搜索:紧聚焦)
  • ¥15 基于51单片机的厨房煤气泄露检测报警系统设计
  • ¥15 Arduino无法同时连接多个hx711模块,如何解决?