简体   繁体   中英

php laravel blade template not rendering

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.

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.

So this is what I have setup:

laravel/app/routes.php

Route::get('/', function()
{
        return View::make('hello');
});

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

<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?

To use a blade template you must have the .blade in file name, for example in your case it should be

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

@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

on your 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.

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. ;)

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') .

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.

Greets, McPan

嗨有同样的问题,我仔细检查了我的代码,结果我省略了一个$为我的变量和页面是空白无法呈现,但这是与流明,希望你也可以仔细检查你的代码

将@extends()放在第一行。

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.

对我而言,这是由于括号之间的空格:而不是{{$ name}}我使用{{$ name}}并且它对我有效。

我面临同样的问题,解决方案是@extends('layouts.master')必须在第一行。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM