类比Laravel的[@extends @yield]和JS的[导出导入]@yield('标题')<...</desc> <question vote="0"> <p>我对 Laravel 布局的理解是:<br/> main.blade.php 将<strong>导入</strong>带有@yield的部分代码:</p> <pre><code><!-- main.blade.php --> <html> <head> <title>@yield('title')</title> </head> <body> @yield('content') </body> </html> </code></pre> <p>部分代码将<strong>导出</strong>自身到特定文件:</p> <pre><code><!-- partial.blade.php --> @extends('layouts.main') @section('title', 'Page Title') @section('content') <p>This is the content of the page.</p> @endsection </code></pre> <p>如果我理解正确的话,是部分本身决定去哪里? <br/> 如果是这样,我就头疼了...我不明白其中的逻辑。<br/> 如果多个视图想要使用相同的部分会发生什么?为什么不是反过来(<pre><code>@yield('layouts.partial','title')</code></pre>),就像在 JS 中一样,导入部分的表示它的路径?</p> </question> <answer tick="false" vote="0"> <p>我认为你的想法是错误的。部分或组件不会扩展布局。它们按原样通过 <pre><code>@component('components.modal')</code></pre> 或 <pre><code>@include('partials.paginate')</code></pre> 包含在内。</p> <p>你这里有什么:</p> <pre><code><!-- partial.blade.php --> @extends('layouts.main') @section('title', 'Page Title') @section('content') <p>This is the content of the page.</p> @endsection </code></pre> <p>不是部分。</p> <p>这是您通过 <pre><code>return view('path.to.view');</code></pre> 提供服务的页面 布局不是页面,否则您将提供布局。此页面现在可以定义(但不是必须)它扩展的布局以及它覆盖该布局的哪些部分,<pre><code>title</code></pre> 和 <pre><code>content</code></pre>。</p> </answer> </body></html>

问题描述 投票:0回答:0
laravel laravel-blade
© www.soinside.com 2019 - 2024. All rights reserved.