laravel php laravel刀片模板未呈现
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18939549/
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
php laravel blade template not rendering
提问by slinkhi
I am attempting to setup a basic page using Laravel and twitter bootstrap. I installed Laravel and got the generic "you're here" or w/e image so that seems shiny. For twitter bootstrap, I added in my /public folder the twitter bootstrap files under /resources/js, /resources/css, and /resources/img.
我正在尝试使用 Laravel 和 twitter bootstrap 设置一个基本页面。我安装了 Laravel 并得到了通用的“你在这里”或 w/e 图像,所以看起来很闪亮。对于 twitter 引导程序,我在我的 /public 文件夹中添加了 /resources/js、/resources/css 和 /resources/img 下的 twitter 引导程序文件。
So now I'm trying to make a template for my views, where basically the twitter bootstrap .css files are output in my head tag and the bootstrap.min.js and jquery.js script includes are output just before my closing body tag.
所以现在我正在尝试为我的视图制作一个模板,其中基本上 twitter bootstrap .css 文件在我的 head 标签中输出,而 bootstrap.min.js 和 jquery.js 脚本包含在我关闭 body 标签之前输出。
So this is what I have setup:
所以这就是我的设置:
laravel/app/routes.php
laravel/app/routes.php
Route::get('/', function()
{
return View::make('hello');
});
laravel/app/views/hello.php
laravel/app/views/hello.php
@extends('layouts.master')
@section('content')
<p>This is my body content.</p>
@stop
laravel/app/views/layouts/master.blade.php
laravel/app/views/layouts/master.blade.php
<html>
<head>
@section('head')
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="/resources/css/bootstrap.min.css" rel="stylesheet" media="screen">
@show
</head>
<body>
<div class="container">
@yield('content')
</div>
@section('footer_scripts')
<script src="http://code.jquery.com/jquery.js"></script>
<script src="/resources/js/bootstrap.min.js"></script>
@show
</body>
</html>
But it the blade template doesn't seem to be rendering. This is the output I get:
但是刀片模板似乎没有渲染。这是我得到的输出:
@extends('layouts.master') @section('content')
This is my body content.
@stop
That's how it looks on-page as well as in the view-source. No html tag or script includes; nothing. I must be missing something basic, and I've tried looking through the Laravel docs, but I can't seem to figure out what I'm doing wrong.. can someone point me in the right direction?
这就是它在页面和视图源中的外观。不包含 html 标签或脚本;没有。我一定遗漏了一些基本的东西,我试过查看 Laravel 文档,但我似乎无法弄清楚我做错了什么..有人能指出我正确的方向吗?
回答by The Alpha
To use a blade template you must have the .blade
in file name, for example in your case it should be
要使用刀片模板,您必须具有.blade
in 文件名,例如在您的情况下它应该是
hello.blade.php
Otherwise, it won't render. Read more on Laravel Site.
Here is an example from one of my testing projects (index.blade.php), since you had a typo @extends('layout.master')
it should be something like this
否则,它不会渲染。在Laravel 网站上阅读更多内容。这是我的一个测试项目 (index.blade.php) 中的一个例子,因为你有一个错字,@extends('layout.master')
它应该是这样的
@extends('layouts.master')
@section('content')
This is a sample of laravel 4 using blade template engine.
This is home page using HomeController and home.blade template.
@stop
回答by reikyoushin
on your laravel/app/views/hello.php
在你的 laravel/app/views/hello.php
that file should have been hello.blade.php
since you want to use blade templating engine with it.. thats it.
那个文件应该是hello.blade.php
因为你想用它来使用刀片模板引擎......就是这样。
more information on templating can be found on the docs
有关模板的更多信息可以在文档中找到
also, on the part where you declare the scripts:
此外,在您声明脚本的部分:
<script src="/resources/js/bootstrap.min.js"></script>
it could be done using this: see this
可以使用这个来完成:看这个
{{ HTML::script('resources/js/bootstrap.min.js') }}
just so you know. ;)
只是让你知道。;)
回答by McPan
Just got the same problem as described initially. But: all template filenames matches required specification with *.blade.php. Also 'layouts' pathname was set correct. Result was still no blade rendering, output was limited to @extends('layouts.master')
.
刚刚遇到与最初描述的相同的问题。但是:所有模板文件名都与 *.blade.php 匹配所需的规范。'layouts' 路径名也设置正确。结果仍然没有刀片渲染,输出被限制为@extends('layouts.master')
.
Solution was: I've used a copy-paste view script with <!-- app/views/index.blade.php -->
comment on the first line. Removing this comment from the template and putting @extends('layouts.master')
on the first line of my view script instead did the trick.
解决方案是:我<!-- app/views/index.blade.php -->
在第一行使用了带有注释的复制粘贴视图脚本。从模板中删除此注释并将其放在@extends('layouts.master')
我的视图脚本的第一行中就可以了。
Greets, McPan
你好,麦克潘
回答by Junior_swashluv
Hi had the same problem and i double checked my code, turns out I had omitted a $ for my variable and the page was blank couldn't be rendered, but this was with lumen, hope you can double check your code too
您好,我遇到了同样的问题,我仔细检查了我的代码,结果我的变量省略了 $ 并且页面空白无法呈现,但这是流明,希望您也可以仔细检查您的代码
回答by Kevin K
I too faced the same problem, then I found, leaving a space or a line before @extends('layouts.master'), or any comments, will not render. @extends('layouts.master') should be placed at top most.
我也遇到了同样的问题,然后我发现,在@extends('layouts.master') 之前留一个空格或一行,或者任何注释都不会呈现。@extends('layouts.master') 应该放在最上面。
回答by user2957058
place @extends() in the first line.
将@extends() 放在第一行。
回答by Rajon Tanducar
for me it was due to space between parenthesis: instead of { {$name} } i used {{$name}} and it worked for me.
对我来说,这是由于括号之间的空格:而不是 { {$name} } 我使用了 {{$name}} 并且它对我有用。
回答by szatti1489
I faced the same problem and the solution is that the @extends('layouts.master')
has to be in the very first line.
我遇到了同样的问题,解决方案是@extends('layouts.master')
必须在第一行。