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

11 Answered Questions

[SOLVED] How to concatenate strings in twig

1 Answered Questions

Twig templates extending

2 Answered Questions

[SOLVED] Twig: Include block of another template

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

3 Answered Questions

[SOLVED] Extend Twig template without blocks

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

1 Answered Questions

[SOLVED] Combining optional block with element in twig

  • 2013-10-30 13:05:27
  • Inca
  • 668 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
  • 6285 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
  • 15112 View
  • 10 Score
  • 2 Answer
  • Tags:   symfony twig assetic

Sponsored Content