Twig templates, inheritances and block usage

Posted by user846226 on Stack Overflow See other posts from Stack Overflow or by user846226
Published on 2012-12-12T19:46:12Z Indexed on 2012/12/13 11:05 UTC
Read the original article Hit count: 300

Filed under:
|

I've created three templates using Twig. The first one has block A defined in it, the second one extends from the first one, but includes a third template which sets the content of block A.

When loading, through the browser, the url which renders b.html.twig, the content in block A (defined by the 3th template) is not positioned block _A is defined.

Example:

<!-- base.html.twig -->
{% block _css '' %}

{% block _header '' %}
{% block _content '' %}
{% block _footer '' %}

{% block _js '' %}


<!-- layout.html.twig -->
<!-- header and footer are placed in the raight zone -->
{% extends ::base.html.twig %}

{% block _header %}
    {% render "MyBundleBundle:Header:header"  %}
{% endblock %}

{% block _footer %}
    {% render "MyBundleBundle:Footer:footer" %}
{% endblock %}


<!-- my_template.html.twig -->
<!-- content is also placed in the right zone but css and js blocks in the included     template are not placed where declared in base.html.twig -->
{% extends MyBundleBundle::layout.html.twig %}
{% block _content %}
     SOME_CONTENT
     {% include MyBundleBundle::my_included_template.html.twig %}
{% endblock %}


<!-- my_included_template.html.twig -->
{% block _css %}
 <link.......................>
{% endblock %}

{% block _js %}
 <script..................>
{% endblock %}

MORE CONTENT BELONGING TO THE INCLUDED TEMPLATE

What i expect here is, _css blocks content to appear on top of the page and _js block content at the bottom, but that's not happening. I hope you can see where i'm going wrong, thanks!

© Stack Overflow or respective owner

Related posts about php

Related posts about twig

  • Another Twig Improvements

    as seen on Oracle Blogs - Search for 'Oracle Blogs'
    Hi all! We are here again to intorduce you some of our new NetBeans 7.3 features. Today we'll show you some another Twig improvements. So let's start! Code Templates First feature is about Code Templates. We added some basic templates to improve your Editor experience. You will be really… >>> More

  • Symfony2 Include in html in Twig

    as seen on Stack Overflow - Search for 'Stack Overflow'
    I am developing an application usin Symfony2 and twig for templates. I am using a 3 level structure for templates. Base.html.twig, layout.html.twig and childtemplate.html.twig. The problem is I am trying to include one example.html (common html file) in the next child template by using include but… >>> More

  • Twig Code Completion

    as seen on Oracle Blogs - Search for 'Oracle Blogs'
    Hi all! After few weeks we have a new feature for you which will be available in upcoming NetBeans 7.3. It's about new code completion in Twig files! So let us introduce it a bit. Now we hopefully support all of Twig built-in elements. It means Tags, Filters, Functions, Tests and Operators… >>> More

  • Twig Template For loop Results

    as seen on Stack Overflow - Search for 'Stack Overflow'
    I am trying to print out a the contents of an array but am not getting the expected results. any help is much appreciated: PHP code: $list[1]['first_name'] = 'Joe'; $list[1]['last_name'] = 'Smith'; $list[2]['first_name'] = 'John'; $list[2]['last_name'] = 'brand'; $data = array( 'customer'… >>> More

  • Twig templates, inheritances and block usage

    as seen on Stack Overflow - Search for 'Stack Overflow'
    I've created three templates using Twig. The first one has block A defined in it, the second one extends from the first one, but includes a third template which sets the content of block A. When loading, through the browser, the url which renders b.html.twig, the content in block A (defined by the… >>> More