<p>Try to keep the blocks separate in your child template. That's how it's done in a <a href="http://twig.sensiolabs.org/doc/tags/extends.html#child-template" rel="noreferrer">comparable example</a> in the Twig Documentation.</p>

<p>Parent Template:</p>

<pre><code>{% block breadcrumbs %}
    {% block crumb %} 
    {% endblock %}
{% endblock %}
</code></pre>

<p>Child Template:</p>

<pre><code>{% extends "parent.html" %}

{% block breadcrumbs %}
    {{ parent() }}
{% endblock %}

{% block crumb %}
    My custom content
{% endblock %}
</code></pre>

<p>.</p>

<p><em>Edit:</em></p>

<p>If you're not adding any content to your "breadcrumbs" block from the child template, you can also omit that block completely:</p>

<pre><code>{% extends "parent.html" %}

{% block crumb %}
    My custom content
{% endblock %}
</code></pre>

CC BY-SA 3.0
2014-08-17T01:09:10.960Z
Hey @carlcs that does not work for me either. It is still hitting the parent block crumb content
Matt
CC BY-SA 3.0
2014-08-19T13:16:26.363Z
Hey @carlcs you are right. This does work as you've suggested. However, I can only get it to work with other blocks. There seems to be some error with my crumb block which is not working for me. Thanks for your help.
Matt
CC BY-SA 3.0
2014-08-16T22:02:06.623Z
2014-08-18T10:16:53.230Z
2014-08-18T10:16:53.230Z
carlcs
<p>I'm not sure if it is appropriate to post twig questions on this forum? I have a question about nested blocks and using the twig "parent" function. I'm running into unexpected behaviour on a craft site i'm building. </p>

<h2>My parent and child template layouts.</h2>

<pre><code>{# Parent Template #}
{% block breadcrumbs %}
    {% block crumb %}

    {% endblock %}
{% endblock %}

{# Child Template #}
{% block breadcrumbs %}
    {{ parent() }}
    {% block crumb %}
        My custom content
    {% endblock %}
{% endblock %}
</code></pre>

<h2>What I'm trying to achieve</h2>

<ul>
<li>On my child template, I'm trying to retain the content in block breadcrumbs but override the content in block crumb.</li>
<li>However when I use the parent function in my child template, it does not respect "my custom content" and uses the block crumb content defined in the parent template.</li>
</ul>

CC BY-SA 3.0
2014-08-17T03:01:57.960Z
Who you ever add content after the crumb block?
Luke Holder
CC BY-SA 3.0
2014-08-18T10:35:11.777Z
Tested your code, Matt. I do get the parent's "breadcrumbs" content with the `parent()` function and I also get the child's "crumb" content with this. Problematic though, you'll get "My custom content" twice if you're nesting the blocks in the child layout. But that is as expected, if you think about it.
carlcs
<templating>
How to use twig parent function on nested blocks
# How to use twig parent function on nested blocks

(Asked by: username_0 on 2014-08-16)

I'm not sure if it is appropriate to post twig questions on this forum? I have a question about nested blocks and using the twig "parent" function. I'm running into unexpected behaviour on a craft site i'm building. 
My parent and child template layouts.
{# Parent Template #}
{% block breadcrumbs %}
    {% block crumb %}

    {% endblock %}
{% endblock %}

{# Child Template #}
{% block breadcrumbs %}
    {{ parent() }}
    {% block crumb %}
        My custom content
    {% endblock %}
{% endblock %}

What I'm trying to achieve

On my child template, I'm trying to retain the content in block breadcrumbs but override the content in block crumb.
However when I use the parent function in my child template, it does not respect "my custom content" and uses the block crumb content defined in the parent template.

**Tags:** templating
> **Comments:**
> **username_1**: Who you ever add content after the crumb block?  
> **username_2**: Tested your code, Matt. I do get the parent's "breadcrumbs" content with the `parent()` function and I also get the child's "crumb" content with this. Problematic though, you'll get "My custom content" twice if you're nesting the blocks in the child layout. But that is as expected, if you think about it.  

---

## 1 answers

### Answer by username_2 on 2014-08-16. Score: 7 | Accepted answer

Try to keep the blocks separate in your child template. That's how it's done in a comparable example in the Twig Documentation.
Parent Template:
{% block breadcrumbs %}
    {% block crumb %} 
    {% endblock %}
{% endblock %}

Child Template:
{% extends "parent.html" %}

{% block breadcrumbs %}
    {{ parent() }}
{% endblock %}

{% block crumb %}
    My custom content
{% endblock %}

.
Edit:
If you're not adding any content to your "breadcrumbs" block from the child template, you can also omit that block completely:
{% extends "parent.html" %}

{% block crumb %}
    My custom content
{% endblock %}

> **Comments:**
> **username_0**: Hey @carlcs that does not work for me either. It is still hitting the parent block crumb content  
> **username_0**: Hey @carlcs you are right. This does work as you've suggested. However, I can only get it to work with other blocks. There seems to be some error with my crumb block which is not working for me. Thanks for your help.  

---

