我如何在laravel中包含扩展布局文件?

时间:2020-11-10 07:43:03

标签: php laravel php-7.2 laravel-6.2

根据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,但视图内容未加载其中。 enter image description here

您可以看到标题两次。

有人可以帮我吗?

2 个答案:

答案 0 :(得分:0)

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

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

将其用于包含不同的布局,并在各部分分开(如果其他则分开)。

答案 1 :(得分:0)

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

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

@section('title')
Home
@endsection

@section('content')
{{-- Some Content  --}}
@endsection