Problem with @extends in view in Laravel.

7

I'm having a problem with @extends('layouts.template') . Only my view that is like index that does not show the page, instead shows me only this @extends('layouts.template') on the page. What could it be?

obs: the route is normal:

Route::any('/', ["as" => "home",
    function() {
        if (Auth::guest())
            return View::make('hello');
        return Redirect::to('list');
    }
]);

this is hello.blade.php :

@extends('layouts.template')

@section('body')

<div class="container">
    <nav class="navbar navbar-default" role="navigation">
        <div class="navbar-header">
            <a href="{{ action('TaskController@listar') }}" class="navbar-brand">TASKS LIST</a>
        </div>
    </nav>
</div>
@stop

and this is template.blade.php :

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <title>ToDoVel - Laravel To-Do</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="description" content="">
    <meta name="author" content="">

        <!-- Le styles -->

    <link rel="stylesheet" href="{{ asset('assets/css/bootstrap.min.css') }}" />

    <style type="text/css">
      body {
        padding-top: 20px;
        padding-bottom: 40px;
      }

      /* Custom container */
      .container-narrow {
        margin: 0 auto;
        max-width: 700px;
      }
      .container-narrow > hr {
        margin: 30px 0;
      }

      /* Main marketing message and sign up button */
      .jumbotron {
        margin: 60px 0;
        text-align: center;
      }
      .jumbotron h1 {
        font-size: 72px;
        line-height: 1;
      }
      .jumbotron .btn {
        font-size: 21px;
        padding: 14px 24px;
      }

      /* Supporting marketing content */
      .marketing {
        margin: 60px 0;
      }
      .marketing p + h4 {
        margin-top: 28px;
      }
    </style>


    <link rel="stylesheet" href="{{ asset('assets/css/bootstrap-responsive.css') }}" />


    <!-- HTML5 shim, for IE6-8 support of HTML5 elements -->
    <!--[if lt IE 9]>
        <link rel="stylesheet" href="{{ asset('assets/js/html5shiv.js') }}" />
    <![endif]-->

    <!-- Fav and touch icons -->
    <link rel="apple-touch-icon-precomposed" sizes="144x144" href="assets/ico/apple-touch-icon-144-precomposed.png">
    <link rel="apple-touch-icon-precomposed" sizes="114x114" href="assets/ico/apple-touch-icon-114-precomposed.png">
      <link rel="apple-touch-icon-precomposed" sizes="72x72" href="assets/ico/apple-touch-icon-72-precomposed.png">
                    <link rel="apple-touch-icon-precomposed" href="assets/ico/apple-touch-icon-57-precomposed.png">
                                   <link rel="shortcut icon" href="assets/ico/favicon.png">
  </head>

  <body>
<div class="container-narrow">

  <div class="masthead">
    <ul class="nav nav-pills pull-right">
      <li><a href="{{ URL::to('/') }}">Home</a></li>
      <li><a href="{{ URL::to('about') }}">About</a></li>
    </ul>
    <h3 class="muted"> Listas de Tarefas </h3>

  </div>

  <hr>

  @section('body')

  <div class="jumbotron">
    <h1>Super awesome marketing speak!</h1>
    <p class="lead">Cras justo odio, dapibus ac facilisis in, egestas eget quam. Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus.</p>
    <a class="btn btn-large btn-success" href="#">Sign up today</a>
  </div>

  <hr>

  <div class="row-fluid marketing">
    <div class="span6">
      <h4>Subheading</h4>
      <p>Donec id elit non mi porta gravida at eget metus. Maecenas faucibus mollis interdum.</p>

      <h4>Subheading</h4>
      <p>Morbi leo risus, porta ac consectetur ac, vestibulum at eros. Cras mattis consectetur purus sit amet fermentum.</p>

      <h4>Subheading</h4>
      <p>Maecenas sed diam eget risus varius blandit sit amet non magna.</p>
    </div>

    <div class="span6">
      <h4>Subheading</h4>
      <p>Donec id elit non mi porta gravida at eget metus. Maecenas faucibus mollis interdum.</p>

      <h4>Subheading</h4>
      <p>Morbi leo risus, porta ac consectetur ac, vestibulum at eros. Cras mattis consectetur purus sit amet fermentum.</p>

      <h4>Subheading</h4>
      <p>Maecenas sed diam eget risus varius blandit sit amet non magna.</p>
    </div>
  </div>
  @show

  <hr>

  <div class="footer">
    <p>Criado por <a href="http://www.FReNeTiC.com.br">FReNeTiC</a></p>
  </div>

</div> <!-- /container -->

<!-- Le javascript
================================================== -->
<!-- Placed at the end of the document so the pages load faster -->
<link rel="stylesheet" href="{{ asset('assets/js/jquery.js') }}" />

<script src="{{ URL::to('/') }}/assets/js/bootstrap-transition.js"></script>
<script src="{{ Request::root() }}/assets/js/bootstrap-transition.js"></script>

<!--<script src="assets/js/jquery.js"></script>
<script src="assets/js/bootstrap-transition.js"></script>
<script src="assets/js/bootstrap-alert.js"></script>
<script src="assets/js/bootstrap-modal.js"></script>
<script src="assets/js/bootstrap-dropdown.js"></script>
<script src="assets/js/bootstrap-scrollspy.js"></script>
<script src="assets/js/bootstrap-tab.js"></script>
<script src="assets/js/bootstrap-tooltip.js"></script>
<script src="assets/js/bootstrap-popover.js"></script>
<script src="assets/js/bootstrap-button.js"></script>
<script src="assets/js/bootstrap-collapse.js"></script>
<script src="assets/js/bootstrap-carousel.js"></script>
<script src="assets/js/bootstrap-typeahead.js"></script>-->

@section('custom_script')
@show

    
asked by anonymous 19.12.2013 / 11:44

2 answers

8

Make sure your files have the extension .blade.php and not just .php

To support other Template systems Laravel allows custom views, which do not use Blade, this is the case of the hello.php file, which does not use Blade, so that its @extends() works you should rename it to hello.blade.php

The View::make() method can identify the two extensions, so you do not need to change anything on your route.

Editing: The problem was due to the encoding of the file, Laravel recognized some character before extends ("layout.layout"), and therefore did not render.

Step by step to solve the problem:

1) Check if the file has .blade.php extension

2) Make sure @extends ('nomedolayout') is the first View statement.

3) Re-create the file, to avoid any possible coding problem, that prevents the @extends from being recognized as the beginning of the file.

    
19.12.2013 / 11:57
1

On your template.blade.php you used:

@section('body') 

and the correct one would be

@yield('body')

If you want to use with section, in your view that extends template.blade.php you will use

@section('body')
@parent
//Conteudo da Seção
@stop

link

    
19.12.2013 / 16:56