Blade 语法 @extends 加载第二个 HTML 视图,然后加载第一个 HTML 视图
Blade syntax @extends loads second HTML view and then the first HTML view
我是 laravel 和 blade 模板引擎的新手。
问题:文件 form.blade.php
@extends('front.header')
@extends('front.footer')
首先加载 front/footer.blade.php,然后加载 front/header.blade.php
的内容
查看源代码的快照随附。
我在 Whosebug 中检查了几个关于白色的答案 space.I 似乎没有。
此致,
吉涅什
您不能 @extends
来自 2 parents。如果你想包含另一个视图,你应该使用 @include
而不是
像这样:
@include('front.header')
Content
@include('front.footer')
这就是我建议您构建主模板的方式。
front._layouts.master:
<!DOCTYPE html>
<html>
<head>
@include('front._layouts.head')
</head>
<body>
<header>
@include('front._layouts.header')
</header>
<main>
@yield('content')
</main>
<footer>
@include('front._layouts.header')
</footer>
@stack('scripts')
</body>
</html>
请注意 @stack()
这在您构建应用程序的健壮部分时非常有用。 Stacks 允许您将命名堆栈推送到彼此之上。
按照以下步骤操作:
第 1 步:
resources\views create a file like: master.blade.php
第 2 步:
resources\views create a folder like: layouts
在 layout
文件夹中创建您的 header
& footer
文件
第 3 步:
里面 master.blade.php
写下你是如何设计你的主模板的。
<!DOCTYPE html>
<html lang="en">
<head>
<!-- your common css here -->
@yield('partial-css')
</head>
<body>
@include('layouts.top-header')
<div class="container">
@yield('content') <!-- this is your common body -->
</div> <!-- /container -->
@include('layouts.footer')
<!-- your common js here or you also define inside the footer page -->
@yield('script') <!-- this is your individual script for all page -->
</body>
</html>
第 4 步:
现在,您可以像这样对所有其他页面使用母版页 index.blade.php
@extends('master')
@section('content')
<!-- Here is your main body content -->
@endsection
@section('script')
<!-- Here is your individual script content -->
@endsection
希望您现在了解 blade 模板的工作原理!
我是 laravel 和 blade 模板引擎的新手。 问题:文件 form.blade.php
@extends('front.header') @extends('front.footer')
首先加载 front/footer.blade.php,然后加载 front/header.blade.php
的内容查看源代码的快照随附。
我在 Whosebug 中检查了几个关于白色的答案 space.I 似乎没有。
此致,
吉涅什
您不能 @extends
来自 2 parents。如果你想包含另一个视图,你应该使用 @include
而不是
像这样:
@include('front.header')
Content
@include('front.footer')
这就是我建议您构建主模板的方式。
front._layouts.master:
<!DOCTYPE html>
<html>
<head>
@include('front._layouts.head')
</head>
<body>
<header>
@include('front._layouts.header')
</header>
<main>
@yield('content')
</main>
<footer>
@include('front._layouts.header')
</footer>
@stack('scripts')
</body>
</html>
请注意 @stack()
这在您构建应用程序的健壮部分时非常有用。 Stacks 允许您将命名堆栈推送到彼此之上。
按照以下步骤操作:
第 1 步:
resources\views create a file like: master.blade.php
第 2 步:
resources\views create a folder like: layouts
在 layout
文件夹中创建您的 header
& footer
文件
第 3 步:
里面 master.blade.php
写下你是如何设计你的主模板的。
<!DOCTYPE html>
<html lang="en">
<head>
<!-- your common css here -->
@yield('partial-css')
</head>
<body>
@include('layouts.top-header')
<div class="container">
@yield('content') <!-- this is your common body -->
</div> <!-- /container -->
@include('layouts.footer')
<!-- your common js here or you also define inside the footer page -->
@yield('script') <!-- this is your individual script for all page -->
</body>
</html>
第 4 步:
现在,您可以像这样对所有其他页面使用母版页 index.blade.php
@extends('master')
@section('content')
<!-- Here is your main body content -->
@endsection
@section('script')
<!-- Here is your individual script content -->
@endsection
希望您现在了解 blade 模板的工作原理!