<p>The code block you have outlined above calls for a third template. Take a look at this fiddle to see how the nesting would work.</p>

<p><a href="http://twigfiddle.com/ul64wd" rel="nofollow">http://twigfiddle.com/ul64wd</a></p>

CC BY-SA 3.0
2016-06-06T12:02:12.380Z
2016-06-06T12:02:12.380Z
Fyrebase
<p>You aren't able to nest <code>blocks</code> in the template where that block is output - all content inside a block in the parent template is replaced by the child templates content, hence why you don't see your content block being output inside your head block. Likewise you can't use multiple <code>extends</code> within one template.</p>

<p>You can however nest blocks in a child template and output them in your extended template.</p>

<p><code>Base.twig</code> (main template)</p>

<pre><code>// Will display "content" and "sidebar content"
{% block content %}{% endblock %}

// Will only display "sidebar content"
{% block sidebar %}{% endblock %}
</code></pre>

<p><code>Child.twig</code></p>

<pre><code>{% extends "Base.twig" %}

{% block content %}
  Content
  {% block sidebar %}
    Sidebar content
  {% endblock %}
{% endblock %}
</code></pre>

<p>More info on the topic can be found in <a href="http://twig.sensiolabs.org/doc/tags/extends.html" rel="nofollow">Twigs documentation</a>.</p>

CC BY-SA 3.0
2016-06-06T11:36:05.017Z
If i can't nest `blocks`, then why the twig doc you linked has this code:          `{% block sidebar %}
    {% block inner_sidebar %}
        ...
    {% endblock inner_sidebar %}
{% endblock sidebar %}`
Keanu Kent Gargar
CC BY-SA 3.0
2016-06-06T11:43:55.037Z
I could somehow get how the extends, parent-child relationship and blocks work just a little, i see that as a starting point for learning. Thanks for answering.
Keanu Kent Gargar
CC BY-SA 3.0
2016-06-06T12:00:15.420Z
Updated answer to be clearer about where you can/can't nest blocks with an example.
Luke Pearce
CC BY-SA 3.0
2016-06-06T11:28:21.057Z
2016-06-07T08:46:39.520Z
2016-06-07T08:46:39.520Z
Luke Pearce
<p>I'm using twigfiddle.com for now because i want to simulate Twig templates before moving on using Craft.</p>

<p><code>Base.twig</code> (main template)</p>

<pre><code>{% block head %}
    {% block content %}{% endblock %}
{% endblock %}
</code></pre>

<p><code>Child.twig</code></p>

<pre><code>{% extends "Base.twig" %}

{% block content %}
    Content from child.twig
{% endblock %}
</code></pre>

<p>I expect an output of "Content from child.twig" but instead get nothing.</p>

<templating>
Twig: Parent template does not inherent what's ever inside the child template even using extends in the child
# Twig: Parent template does not inherent what's ever inside the child template even using extends in the child

(Asked by: username_0 on 2016-06-06)

I'm using twigfiddle.com for now because i want to simulate Twig templates before moving on using Craft.
Base.twig (main template)
{% block head %}
    {% block content %}{% endblock %}
{% endblock %}

Child.twig
{% extends "Base.twig" %}

{% block content %}
    Content from child.twig
{% endblock %}

I expect an output of "Content from child.twig" but instead get nothing.

**Tags:** templating


---

## 2 answers

### Answer by username_2 on 2016-06-06. Score: 4 | Accepted answer

You aren't able to nest blocks in the template where that block is output - all content inside a block in the parent template is replaced by the child templates content, hence why you don't see your content block being output inside your head block. Likewise you can't use multiple extends within one template.
You can however nest blocks in a child template and output them in your extended template.
Base.twig (main template)
// Will display "content" and "sidebar content"
{% block content %}{% endblock %}

// Will only display "sidebar content"
{% block sidebar %}{% endblock %}

Child.twig
{% extends "Base.twig" %}

{% block content %}
  Content
  {% block sidebar %}
    Sidebar content
  {% endblock %}
{% endblock %}

More info on the topic can be found in Twigs documentation.

> **Comments:**
> **username_0**: If i can't nest `blocks`, then why the twig doc you linked has this code:          `{% block sidebar %}     {% block inner_sidebar %}         ...     {% endblock inner_sidebar %} {% endblock sidebar %}`  
> **username_0**: I could somehow get how the extends, parent-child relationship and blocks work just a little, i see that as a starting point for learning. Thanks for answering.  
> **username_2**: Updated answer to be clearer about where you can/can't nest blocks with an example.  

---

### Answer by username_1 on 2016-06-06. Score: 1

The code block you have outlined above calls for a third template. Take a look at this fiddle to see how the nesting would work.

<http://twigfiddle.com/ul64wd>


---

