laravel:如何从刀片布局中包含部分?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/23590459/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
laravel: how do I include partials from a blade layout?
提问by dave dave
I'd like to split my layouts into partials.
我想将我的布局分成部分。
I'm creating a default blade layout.
我正在创建一个默认的刀片布局。
The file is called default.blade.php, and lives in the layout
folder.
该文件名为default.blade.php,位于layout
文件夹中。
Also under the layout folder is include
.
In this dir, I have head.blade.php
布局文件夹下还有include
. 在这个目录中,我有head.blade.php
I would like to call 'head' from 'default'.
我想从“默认”中调用“头”。
Every one of these fails and returns an error when debug is turned on:
当调试打开时,这些中的每一个都失败并返回错误:
@include('include/head'), @include('include/head.blade.php'), @include('include/head.blade.php')
I have copied head.blade.phpinto the same folder as default.blade.php, and still get errors.
我已将head.blade.php复制到与default.blade.php相同的文件夹中,但仍然出现错误。
回答by David Barker
You need to give the full path relative to your view folder. Try doing this :
您需要提供相对于您的视图文件夹的完整路径。尝试这样做:
@include('layout.include.head')
回答by Cranio
Keep in mind that Laravel uses dot notation to organize the templates and their parts.
请记住,Laravel 使用点符号来组织模板及其部分。
So, the main.blade.php
template in your main /views
folder should be included directly:
因此,应直接包含main.blade.php
主/views
文件夹中的模板:
@include ('main')
@include ('main')
A main.blade.php
template in a, e.g. /views/layouts
folder should be called as:
一个main.blade.php
在一个模板,如/views/layouts
文件夹应该被称为:
@include ('layouts.main')
@include ('layouts.main')
and so on.
等等。