Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 954
slinkhi Avatar asked Sep 22 '13 01:09

slinkhi


People also ask

Can we write PHP code in blade template Laravel?

Blade is the simple, yet powerful templating engine that is included with Laravel. Unlike some PHP templating engines, Blade does not restrict you from using plain PHP code in your templates.

Can I use blade template without Laravel?

You could download the class and start using it, or you could install via composer. It's 100% compatible without the Laravel's own features (extensions).

Why does Laravel use the blade template engine?

Laravel Blade template engine enables the developer to produce HTML based sleek designs and themes. All views in Laravel are usually built in the blade template. Blade engine is fast in rendering views because it caches the view until they are modified. All the files in resources/views have the extension .

What is the advantage of Laravel blade template?

The blade templates are stored in the /resources/view directory. The main advantage of using the blade template is that we can create the master template, which can be extended by other files.


1 Answers

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
like image 108
The Alpha Avatar answered Sep 30 '22 22:09

The Alpha