【问题标题】:why does repete @section content in Laravel为什么在 Laravel 中重复 @section 内容
【发布时间】:2021-03-20 10:35:47
【问题描述】:

使用 Laravel,我有以下欢迎页面

</head>
<body>
</div><!--container-->
        @include('partials._footer')
        @endsection

        @else

        @section('fixx')
        <p>Rivers</p>
        @endsection
        @endguest
    </body>
</html>

和 app.blade.php

 @guest
        <main class="py-4">
        @yield('content')
        </main>
        @else
        <main class="py-4">
        @include('partials._nav')
        
            @yield('fixx')
            
            @include('partials._footer')   
        </main>
        @endguest

_nav.blade.php

<link rel="stylesheet" href="{{ URL::asset('css/nav.css') }}" />

<div class="d-flex" id="wrapper">
<!-- Page Content -->
    @yield('one')
    @if('Auth')
    @yield('two')
    @endif
</div>

但是当我看到登录用户的欢迎页面时,我可以在 @yield('two') 中看到 @yield('one') 内容

我该如何解决这个问题?

【问题讨论】:

  • 我认为您的@if('Auth') 条件是错误的。你能改用@auth 吗?
  • 此处产生错误

标签: php html css laravel


【解决方案1】:

如果您只想为登录用户显示@yield('two'),请尝试以下操作:

@auth
    @yield('two')
@endauth

顺便说一句,您的标记中缺少一些刀片指令。确保您使用的每个指令都有匹配的开始和结束标记。

https://laravel.com/docs/blade#blade-directives

编辑:

如果您想为登录用户隐藏@yield('one')

// usign @guest
@guest
  @yield('one')
@else
  @yield('two')
@endauth

【讨论】:

  • yield 应该是@yield
  • 我做到了,但它也显示为@yield('one')
  • 你想为登录用户隐藏@yield('one')吗?
猜你喜欢
  • 1970-01-01
  • 2015-06-25
  • 2013-06-24
  • 2014-09-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-11-13
  • 1970-01-01
相关资源
最近更新 更多