【问题标题】:how can i include an extend a layout file in laravel?如何在 laravel 中包含扩展布局文件?
【发布时间】:2021-02-22 03:26:13
【问题描述】:

我很难根据 if else 条件扩展到不同的布局文件

@if($subdomain_alias === "blk")
    @extends("layouts.frontend-new")
    @section('title')
    Home
    @endsection
    @section('content')
    {{-- Some Content  --}}
    @endsection
@else
    @extends('layouts.frontend')
    @section('title')
    Home
    @endsection
    @section('content')
    {{-- Some Content  --}}
    @endsection
@endif

但问题是布局都包含在内,我可以看到所有内容两次。

我尝试使用@include,但视图内容未在其中加载。

你可以看到两次标题。

有人可以帮帮我吗?

【问题讨论】:

标签: php laravel php-7.2 laravel-6.2


【解决方案1】:

我想通了,我只是将条件与布局分开。

@extends((( $subdomain_alias === "blk") ? 'layouts.frontend-new' : 'layouts.frontend' ))

用它来包含不同的布局,如果其他部分则分开。

【讨论】:

    【解决方案2】:

    您需要使用三元运算符在刀片文件的第一行中选择不同的主布局:

    @extends(($subdomain_alias === "blk" ? "layouts.frontend-new" : "layouts.frontend"))
    
    @section('title')
    Home
    @endsection
    
    @section('content')
    {{-- Some Content  --}}
    @endsection
    

    【讨论】:

      猜你喜欢
      • 2023-03-29
      • 2014-12-07
      • 1970-01-01
      • 2023-03-28
      • 2017-12-15
      • 2011-08-03
      • 1970-01-01
      • 1970-01-01
      • 2016-12-13
      相关资源
      最近更新 更多