Problem with @extends in view on Laravel.

Asked

Viewed 2,551 times

7

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

Obs: the route is normal:

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

that’s the 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

  • 1

    Post the contents of both Views, hello.blade.php and layouts/template.blade.php

  • Confirm that the template.blade.php file is in the layouts folder

2 answers

8

Check if the 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 file hello.php, who does not use Blade, so that his @extends() run you should rename it to hello.blade.php

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

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

Step by Step to solve the problem:

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

2) Make sure that @extends('nomedolayout') be the first instruction of the View.

3) Recreate the file, to avoid any possible encoding problem, which prevents @extends from being recognized as the beginning of the file.

  • has yes..... and its I remove and @extends() and insert a template html code in hello.blade.php works fine.... already in the other files works blazinha @extends()

  • Return View::make('hello'); Redirect to the Example View that comes next to Laravel, check if the file exists: app/views/hello.php

1

In his template.blade.php you used:

@section('body') 

and the right thing would be

@yield('body')

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

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

http://laravel.com/docs/templates#Blade-templating

  • looks like an appointment. but the login view continues to blz even after the edit that you got me but hello.blade.php only returns me in the browser @extends('layouts.').....

  • Put the two files on http://paste.laravel.com/ and pass the link to take a look.

  • Flavio http://paste.laravel.com/1fA8

  • Guy made a simple test here: using the file as hello.php gives the problem you reported, already using the file as hello.blade.php works, take a look if you are not with the 2 files: hello.php and hello.blade.php, if they are in the same folder, deletes the wrong or renames it.

  • I checked if I had 2 files, renamed it in the route file changed from @Yield('body') to @Yield('content')... and nothing.... I decided to copy the code of the file and delete it and create a new file with the same code because you believe it worked.... will understand né........ Flavio thank you very much brother.... without forgetting the William and the Hernandes also.... vlw masters

  • @This happens because your editor must have added some character to the beginning of the file (GOOD maybe).

Show 1 more comment

Browser other questions tagged

You are not signed in. Login or sign up in order to post.