By AFA Med


2015-07-09 13:32:30 8 Comments

I have a template child.html.twig that extends parent.html.twig, within the child template, I included a partial _myVar.html.twig which contains a long logic that defines some specific variables.

I got the error : A template that extends another one cannot have a body, I don't understand because the included partial doesdn't output any content, it just defines variables and if its content is just written in child.html.twig the error disappear even outside all blocks.

I wished to put the included partial outside all blocks, but to fix the issue, I included it within one of the overriding blocks.

I got another problem of undefined variable, I don't know why the defined variables within the included partial are not available in the global scope after inclusion.

1 comments

@oshell 2015-07-09 15:44:19

You should have posted your code, but normally you just have to take care of the following:

  • the extends tag should be the first tag in the template
  • every content in your extendig template has to be defined in blocks (those from the parent)

Related Questions

Sponsored Content

1 Answered Questions

Twig templates extending

2 Answered Questions

[SOLVED] Twig: Include block of another template

  • 2017-12-24 12:41:49
  • tungsten
  • 4277 View
  • 6 Score
  • 2 Answer
  • Tags:   symfony twig

0 Answered Questions

Create a function for include template twig

  • 2017-11-19 07:06:52
  • abbas291075
  • 49 View
  • 0 Score
  • 0 Answer
  • Tags:   php templates twig

3 Answered Questions

[SOLVED] Extend Twig template without blocks

  • 2016-04-27 06:13:31
  • barbushin
  • 697 View
  • 1 Score
  • 3 Answer
  • Tags:   twig

0 Answered Questions

Twig variables appear to be out of scope in over-ridden Sonata template

1 Answered Questions

[SOLVED] Nested blocks across template hierarchyā€ˇ in Twig

  • 2014-01-30 15:30:52
  • Raphael Riel
  • 2696 View
  • 1 Score
  • 1 Answer
  • Tags:   php twig

1 Answered Questions

[SOLVED] Combining optional block with element in twig

  • 2013-10-30 13:05:27
  • Inca
  • 614 View
  • 0 Score
  • 1 Answer
  • Tags:   twig

1 Answered Questions

[SOLVED] Can I inject javascript blocks from a child template in Symfony2?

  • 2012-07-26 16:31:22
  • codecowboy
  • 6041 View
  • 5 Score
  • 1 Answer
  • Tags:   symfony twig

2 Answered Questions

[SOLVED] Symfony2 Assetic + Twig Template JavaScript Inheritance

  • 2012-01-07 11:20:40
  • JamesHalsall
  • 15083 View
  • 10 Score
  • 2 Answer
  • Tags:   symfony twig assetic

Sponsored Content