php @extends('layout') laravel。刀片模板系统似乎不起作用
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21458885/
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
@extends('layout') laravel. Blade Template System seems like Not working
提问by Luillyfe
I tried to use the laravel's template system: bladebut seems like not working when using the code below in the file users.blade.php:
我尝试使用 laravel 的模板系统:blade但是在文件中使用下面的代码时似乎不起作用users.blade.php:
@extends('layout')
@section('content')
Users! @stop
and browser,
和浏览器,
@extends('layout')
采纳答案by iavery
That should work if you have a template file at /app/views/layout.blade.php that contains
如果您在 /app/views/layout.blade.php 中有一个包含
<p>Some content here</p>
@yield('content')
<p>Some additional content here</p>
Then in your /app/views/user.blade.php, the content
然后在你的 /app/views/user.blade.php 中,内容
@extends('layout')
@section('content')
<p>This is the user content</p>
@stop
If you call return View::make('user')you should have the compiled content
如果你打电话,return View::make('user')你应该有编译的内容
<p>Some content here</p>
<p>This is the user content</p>
<p>Some additional content here</p>
I hope that helps clarify things for you. If not, can you provide your template file locations and the relevant content?
我希望这有助于为你澄清事情。如果没有,您能否提供您的模板文件位置和相关内容?
回答by Neeno Xavier
Just remove the extra space or anything before @extends('yourlayoutfile').
只需删除@extends('yourlayoutfile') 之前的额外空间或任何内容。
It should be the first thing to be rendered in the file.
它应该是文件中呈现的第一件事。
I was facing the same problem and tried many things.Suddenly I found a single space at the starting of the file before @extends.
我遇到了同样的问题并尝试了很多东西。突然我在@extends 之前的文件开头找到了一个空格。
Removed the space and is working fine.
删除了空间并且工作正常。
Thanks.
谢谢。
Format:
格式:
@extends('layouts.default')
@section('content')
.....
@stop
---Edit----
- -编辑 - -
If this didnt work then try :
如果这不起作用,请尝试:
Copy all the content in the file and then delete the file.
复制文件中的所有内容,然后删除文件。
Create a new file and save it as filename.blade.php
创建一个新文件并将其保存为 filename.blade.php
Only after saving the file paste the content into the page. Save the changes and run it.
只有在保存文件后才将内容粘贴到页面中。保存更改并运行它。
This works.
这有效。
Thank you.
谢谢你。
回答by Nam Nguyen
I have the same problem. What is did is: 1. in routes.php
我也有同样的问题。所做的是:1.在routes.php
Route::get('about', 'AboutController@index');
that AboutController is a controller file AboutController.php in app/controllers index is a function inside that controller.
AboutController 是 app/controllers 索引中的控制器文件 AboutController.php 是该控制器内的一个函数。
2.Create AboutController.php in app/controllers
2.在app/controllers中创建AboutController.php
class class AboutController extends BaseController {
protected $layout = 'layouts.default';
$this->layout->content = View::make('pages.about');
}
You can look at this reference: Defining A Layout On A Controller
你可以看看这个参考:Defining A Layout On A Controller
回答by Connor Tumbleson
Where is your layout?
你的布局在哪里?
If its in app/views/layouts, then it should be
如果它在app/views/layouts,那么它应该是
@extends('layouts.index')
(assuming the name is index.blade.php)
(假设名称是 index.blade.php)
ex: @extends('layouts.foo')equals a file in app/views/layouts/called either foo.blade.phpor foo.php. (depending if you use blade)
例如:@extends('layouts.foo')等于一个app/views/layouts/名为foo.blade.phpor 或的文件foo.php。(取决于您是否使用刀片)
回答by The Alpha
By default,Laravelhas a layoutsfolder inside viewsfolder, i.e. app/views/layoutsand in this folder you keep your layout files, i.e. app/views/layouts/index.master.phpand if you have something similar then you should use something like this:
默认情况下,文件夹中Laravel有一个layouts文件views夹,即app/views/layouts在此文件夹中保存布局文件,即app/views/layouts/index.master.php,如果您有类似的内容,则应使用以下内容:
@extends('layouts.master')
@section('content')
<p>Page Content</p>
@stop
This will inherit/use the master.blade.phpfile (as layout) from layoutsfolder, here, layouts.mastermeans layouts/master.blade.php.
这将从master.blade.php文件layouts夹继承/使用文件(作为布局),在这里,layouts.master意味着layouts/master.blade.php.
In your master.blade.phpfile you mast have this
在你的master.blade.php文件中,你必须有这个
@yield('content')
So, data/content from the view between @section('content')and @stopwill be dumped in the place of @yield('content')of your layout.
所以,从之间的视图数据/内容@section('content')和@stop将在地方倾倒@yield('content')你的布局。
You can use any name for your layoutfile, if it's layouts/main.blade.phpthen you should use
您可以为layout文件使用任何名称,如果是layouts/main.blade.php,则应使用
@extends('layouts.main')
回答by Mahdi P.
let's say you have 'master.blade.php' and 'index.blade.php'. and both of files are in views->home directory. when you want to use @extends in 'index.blade.php' by calling 'master.blad.php' , you should write in index.blade.php file this statment:
假设您有“master.blade.php”和“index.blade.php”。并且这两个文件都在 views->home 目录中。当您想通过调用 'master.blad.php' 在 'index.blade.php' 中使用 @extends 时,您应该在 index.blade.php 文件中写入以下语句:
@extends('home.master')
not
不是
@extends('master')
回答by Bongo
Simply save your source using encoding UTF-8 without signature.
只需使用 encoding 保存您的源代码UTF-8 without signature。

