obteniendo el error de que una plantilla que se extiende no puede tener cuerpo

I am working on jobeet tutorial. When I am running the project on localhost like this:

http://localhost/Symfony/web/app_dev.php/ens_job/

Estoy recibiendo un error

A template that extends another one cannot have a body in EnslJobeetBundle:Job:index.html.twig at line 7.

¿Qué debo hacer en este caso?

I am using the index.html.twig as follow:

<!-- src/Ens/JobeetBundle/Resources/views/Job/index.html.twig -->
{% extends 'EnsJobeetBundle::layout.html.twig' %}

{% block stylesheets %}
  {{ parent() }}
  <link rel="stylesheet" href="{{ asset('bundles/ensjobeet/css/jobs.css') }}" type="text/css" media="all" />
{% endblock %}

<!-- the rest of the code -->

preguntado el 31 de julio de 12 a las 12:07

<!-- src/Ens/JobeetBundle/Resources/views/Job/index.html.twig --> {% extends 'EnsJobeetBundle::layout.html.twig' %} {% block stylesheets %} {{ parent() }} <link rel="stylesheet" href="{{ asset('bundles/ensjobeet/css/jobs.css') }}" type="text/css" media="all" /> {% endblock %} <!-- the rest of the code --> -

@thecatontheflat files are on this link gist.github.com/3216535 -

2 Respuestas

This error occurs when you have content out of blocks in child template.

Tienes que eliminar <!-- src/Ensl/JobeetBundle/Resources/views/Job/index.html.twig --> a partir de su index.html.twig

Respondido 31 Jul 12, 13:07

yeah, the prom is solved. this thing is comment na, then why this problem is - Rohitashv Singhal

Any content that is not Twig code must be inside a Twig block. - Federico Krautwald

Or rather, any content that is not Twig code must be within a Twig context, such as a block. (stackoverflow wouldn’t let be edit my previous comment) - Federico Krautwald

Thanks! That was it! - deyvw

Twig doesn't allow any html syntax if you are extending layout. This means that even the comment tags in html is treated as content outside the defined blocks. If you want to retain the comments then you can just do it in twig comments like this:

{# src/Ens/JobeetBundle/Resources/views/Job/index.html.twig #}
{% extends 'EnsJobeetBundle::layout.html.twig' %}
{% block stylesheets %}
  {{ parent() }}
  <link rel="stylesheet" href="{{ asset('bundles/ensjobeet/css/jobs.css') }}" type="text/css" media="all" />
{% endblock %}
{# the rest of the code #}

contestado el 22 de mayo de 15 a las 11:05

This is also an answer that could be selected as apropriate - Herr Nentu '

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.