Php Laravel刀片@包括@产量

Php Laravel刀片@包括@产量,php,laravel,blade,laravel-blade,Php,Laravel,Blade,Laravel Blade,类似的东西在拉威尔刀片可能吗 Route::get('blade', function () { return view('aMainPage'); }); aMainPage.blade.php @include('molecules.blocks.banner', ['background'=> '/image.jpeg']) <h1>I am included</h1> @endinclude @if($background) <sec

类似的东西在拉威尔刀片可能吗

Route::get('blade', function () {
    return view('aMainPage');
});
aMainPage.blade.php

@include('molecules.blocks.banner', ['background'=> '/image.jpeg'])
   <h1>I am included</h1>
@endinclude
@if($background)
<section class="banner" style="background-image:url('{{$background}}');">
@else
<section class="banner">
@endif
    <h1>Hello</h1>
    @yield() {{- notice @yield here -}}
</section>
@if(isset($background))
  <section class="banner" style="background-image:url('{{$background}}');">
@else
  <section class="banner">
@endif
      <h1>Hi</h1>
      @yield('main_content')
</section>
<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>vNull</title>
</head>
<body>
@section('main_content')
    <h1>Woho</h1>
@endsection
@include('molecules.blocks.banner', ['background' => '/image.jpeg'])
</body>
</html>
@if(isset($background))
  <section class="banner" style="background-image:url('{{$background}}');">
@else
  <section class="banner">
@endif
      <h1>Hi</h1>
      @stack('main_content')
</section>
<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>vNull</title>
</head>
<body>
@include('molecules.blocks.banner', ['background' => '/image.jpeg'])
@push('main_content')
    <h1>Woho</h1>
@endpush
</body>
</html>
@include('molecules.blocks.banner',['background'=>'/image.jpeg']))
包括我在内
@包括
/views/molecules/blocks/banner.blade.php

@include('molecules.blocks.banner', ['background'=> '/image.jpeg'])
   <h1>I am included</h1>
@endinclude
@if($background)
<section class="banner" style="background-image:url('{{$background}}');">
@else
<section class="banner">
@endif
    <h1>Hello</h1>
    @yield() {{- notice @yield here -}}
</section>
@if(isset($background))
  <section class="banner" style="background-image:url('{{$background}}');">
@else
  <section class="banner">
@endif
      <h1>Hi</h1>
      @yield('main_content')
</section>
<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>vNull</title>
</head>
<body>
@section('main_content')
    <h1>Woho</h1>
@endsection
@include('molecules.blocks.banner', ['background' => '/image.jpeg'])
</body>
</html>
@if(isset($background))
  <section class="banner" style="background-image:url('{{$background}}');">
@else
  <section class="banner">
@endif
      <h1>Hi</h1>
      @stack('main_content')
</section>
<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>vNull</title>
</head>
<body>
@include('molecules.blocks.banner', ['background' => '/image.jpeg'])
@push('main_content')
    <h1>Woho</h1>
@endpush
</body>
</html>
@if($background)
@否则
@恩迪夫
你好
@yield(){{-notice@yield here-}
所需输出

<section class="banner" style="background-image:url('/image.jpeg');">
    <h1>Hello</h1>
    <h1>I am included</h1>
</section>
 <section class="banner" style="background-image:url('/image.jpeg');">
    <h1>Hello</h1>
</section>


    <h1>I am included</h1>
@endinclude
<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>vNull</title>
</head>
<body>
  <section class="banner" style="background-image:url('/image.jpeg');">
      <h1>Hello</h1>
      <h1>Woho</h1>
  </section>
</body>
</html>

你好
包括我在内

下面是上面当前呈现的内容

实际产出

<section class="banner" style="background-image:url('/image.jpeg');">
    <h1>Hello</h1>
    <h1>I am included</h1>
</section>
 <section class="banner" style="background-image:url('/image.jpeg');">
    <h1>Hello</h1>
</section>


    <h1>I am included</h1>
@endinclude
<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>vNull</title>
</head>
<body>
  <section class="banner" style="background-image:url('/image.jpeg');">
      <h1>Hello</h1>
      <h1>Woho</h1>
  </section>
</body>
</html>

你好
包括我在内
@包括
当然可能

分子/blocks/banner.blade.php

@include('molecules.blocks.banner', ['background'=> '/image.jpeg'])
   <h1>I am included</h1>
@endinclude
@if($background)
<section class="banner" style="background-image:url('{{$background}}');">
@else
<section class="banner">
@endif
    <h1>Hello</h1>
    @yield() {{- notice @yield here -}}
</section>
@if(isset($background))
  <section class="banner" style="background-image:url('{{$background}}');">
@else
  <section class="banner">
@endif
      <h1>Hi</h1>
      @yield('main_content')
</section>
<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>vNull</title>
</head>
<body>
@section('main_content')
    <h1>Woho</h1>
@endsection
@include('molecules.blocks.banner', ['background' => '/image.jpeg'])
</body>
</html>
@if(isset($background))
  <section class="banner" style="background-image:url('{{$background}}');">
@else
  <section class="banner">
@endif
      <h1>Hi</h1>
      @stack('main_content')
</section>
<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>vNull</title>
</head>
<body>
@include('molecules.blocks.banner', ['background' => '/image.jpeg'])
@push('main_content')
    <h1>Woho</h1>
@endpush
</body>
</html>
@if(isset($background))
@否则
@恩迪夫
你好
@产量(“主要内容”)
aMainPage.blade.php

@include('molecules.blocks.banner', ['background'=> '/image.jpeg'])
   <h1>I am included</h1>
@endinclude
@if($background)
<section class="banner" style="background-image:url('{{$background}}');">
@else
<section class="banner">
@endif
    <h1>Hello</h1>
    @yield() {{- notice @yield here -}}
</section>
@if(isset($background))
  <section class="banner" style="background-image:url('{{$background}}');">
@else
  <section class="banner">
@endif
      <h1>Hi</h1>
      @yield('main_content')
</section>
<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>vNull</title>
</head>
<body>
@section('main_content')
    <h1>Woho</h1>
@endsection
@include('molecules.blocks.banner', ['background' => '/image.jpeg'])
</body>
</html>
@if(isset($background))
  <section class="banner" style="background-image:url('{{$background}}');">
@else
  <section class="banner">
@endif
      <h1>Hi</h1>
      @stack('main_content')
</section>
<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>vNull</title>
</head>
<body>
@include('molecules.blocks.banner', ['background' => '/image.jpeg'])
@push('main_content')
    <h1>Woho</h1>
@endpush
</body>
</html>

vNull
@章节(“主要内容”)
沃霍
@端部
@包括('molecules.blocks.banner',['background'=>'/image.jpeg'])
二次溶液

分子/blocks/banner.blade.php

@include('molecules.blocks.banner', ['background'=> '/image.jpeg'])
   <h1>I am included</h1>
@endinclude
@if($background)
<section class="banner" style="background-image:url('{{$background}}');">
@else
<section class="banner">
@endif
    <h1>Hello</h1>
    @yield() {{- notice @yield here -}}
</section>
@if(isset($background))
  <section class="banner" style="background-image:url('{{$background}}');">
@else
  <section class="banner">
@endif
      <h1>Hi</h1>
      @yield('main_content')
</section>
<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>vNull</title>
</head>
<body>
@section('main_content')
    <h1>Woho</h1>
@endsection
@include('molecules.blocks.banner', ['background' => '/image.jpeg'])
</body>
</html>
@if(isset($background))
  <section class="banner" style="background-image:url('{{$background}}');">
@else
  <section class="banner">
@endif
      <h1>Hi</h1>
      @stack('main_content')
</section>
<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>vNull</title>
</head>
<body>
@include('molecules.blocks.banner', ['background' => '/image.jpeg'])
@push('main_content')
    <h1>Woho</h1>
@endpush
</body>
</html>
@if(isset($background))
@否则
@恩迪夫
你好
@堆栈(“主内容”)
aMainPage.blade.php

@include('molecules.blocks.banner', ['background'=> '/image.jpeg'])
   <h1>I am included</h1>
@endinclude
@if($background)
<section class="banner" style="background-image:url('{{$background}}');">
@else
<section class="banner">
@endif
    <h1>Hello</h1>
    @yield() {{- notice @yield here -}}
</section>
@if(isset($background))
  <section class="banner" style="background-image:url('{{$background}}');">
@else
  <section class="banner">
@endif
      <h1>Hi</h1>
      @yield('main_content')
</section>
<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>vNull</title>
</head>
<body>
@section('main_content')
    <h1>Woho</h1>
@endsection
@include('molecules.blocks.banner', ['background' => '/image.jpeg'])
</body>
</html>
@if(isset($background))
  <section class="banner" style="background-image:url('{{$background}}');">
@else
  <section class="banner">
@endif
      <h1>Hi</h1>
      @stack('main_content')
</section>
<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>vNull</title>
</head>
<body>
@include('molecules.blocks.banner', ['background' => '/image.jpeg'])
@push('main_content')
    <h1>Woho</h1>
@endpush
</body>
</html>

vNull
@包括('molecules.blocks.banner',['background'=>'/image.jpeg'])
@推送(“主内容”)
沃霍
@端推
结果

<section class="banner" style="background-image:url('/image.jpeg');">
    <h1>Hello</h1>
    <h1>I am included</h1>
</section>
 <section class="banner" style="background-image:url('/image.jpeg');">
    <h1>Hello</h1>
</section>


    <h1>I am included</h1>
@endinclude
<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>vNull</title>
</head>
<body>
  <section class="banner" style="background-image:url('/image.jpeg');">
      <h1>Hello</h1>
      <h1>Woho</h1>
  </section>
</body>
</html>

vNull
你好
沃霍

我有,但不起作用。我将添加渲染的输出。不要像
@endinclude
这样的东西,要么将其作为一个部分,要么只包含partialHey@xdevnull,谢谢您的回复!我尝试了一下,它看起来很有希望,但我尝试创建的是一个“可重用组件”,我可以在同一个文件中多次使用它。你知道这在blade中是否可行吗?嘿@Jammer在这种情况下,
@include
@stack
将完成这项工作。但是让父对象渲染子对象,而不是像你的问题那样,因为如果你有非常大的文件,似乎很难理解。看这个小例子