slinkhi
slinkhi

Reputation: 989

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?

Upvotes: 10

Views: 21961

Answers (8)

Rajon Tanducar
Rajon Tanducar

Reputation: 378

for me it was due to space between parenthesis: instead of { {$name} } i used {{$name}} and it worked for me.

Upvotes: 0

szatti1489
szatti1489

Reputation: 362

I faced the same problem and the solution is that the @extends('layouts.master') has to be in the very first line.

Upvotes: -1

Kevin K
Kevin K

Reputation: 25

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.

Upvotes: 1

Junior_swashluv
Junior_swashluv

Reputation: 331

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

Upvotes: 2

user2957058
user2957058

Reputation: 330

place @extends() in the first line.

Upvotes: 1

McPan
McPan

Reputation: 21

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

Upvotes: 2

The Alpha
The Alpha

Reputation: 146191

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

Upvotes: 22

reikyoushin
reikyoushin

Reputation: 2021

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

Upvotes: 3

Related Questions