问题
I'm learning Laravel 3, but Blade template is not working. My code seems correct, but all it displays is @layout('master')
. Pages source also contains this text only.
application\views\home\index.blade.php
contents:
@layout('master')
@section('main')
{{ $greeting }}
@endsection
application\views\master.blade.php
contents:
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Hello world!</title>
</head>
<body>
<div id="container">
@yield('main')
</div>
</body>
</html>
and in routes.php
:
Route::get('/, home', function()
{
$greeting = "Hello world";
return View::make('home.index')->with('greeting',$greeting);
});
What can cause blade not to work? I tried Laravel 4 also, and changed @layout
to @extends
, @endsection
to @stop
but same situation. I get only @extends('master')
.
回答1:
Not sure...but I think its because you have a space at the top of your file....
@layout('master')
needs to be directly at the top of the file for it to work properly... Else it just echoes @layout('master') as words to the page, if you know what Im trying to say :)
回答2:
same on me in L4... check your charset of your code editor! sometimes some hidden chars are at the beginning of the file. i switched to "UTF-8 without BOM"
回答3:
Just remove every space or EOL, CR, LF, Enter, \n (or whatever) before your code. Same issue in Laravel 4, I followed the quick start the step where you create a view I leave a new line.
-New line here, and it brokes-
@extends('layout')
@section('content')
Users!
@stop
Again remove anything before @extends('layout')
and it works for me!!
来源:https://stackoverflow.com/questions/16996413/laravel-3-blade-template-is-not-working