<p>I'm going to assume that, as per the use cases <a href="https://twig.sensiolabs.org/doc/1.x/tags/embed.html" rel="nofollow noreferrer">in the documentation</a>, <code>embed</code> is a good fit for your requirements.</p>

<p>If you're not sure, <code>extends</code> and <code>include</code> are probably a better choice, as they're much easier to understand and work with.</p>

<p>Moving on, in your example you appear to have confused the roles of the template being embedded, and the template doing the embedding.</p>

<p>Here's how it should look:</p>

<pre><code>{# Page (doing the embedding) #}
{% embed "_partials/sidebar" %}
    {% block subscribe %}
        The custom subscribe block content.
    {% endblock %}
{% endembed %}

{# Embed (being embedded) #}
&lt;div class="sidebar"&gt;
    &lt;div class="sidebar__subscribe"&gt;
        {% block subscribe %}
            The (optional) default subscribe block content.
        {% endblock %}
    &lt;/div&gt;
&lt;/div&gt;
</code></pre>

CC BY-SA 3.0
2017-05-05T19:12:15.257Z
2017-05-05T20:22:13.210Z
2017-05-05T20:22:13.210Z
Stephen Lewis
<p>I'm trying to embed the sidebar and define which blocks to display.</p>

<pre><code>{% embed "_partials/sidebar" %}
    {% block instagram %}{% endblock %}
    {% block subscribe %}{% endblock %}
{% endembed %}
</code></pre>

<p>sidebar.html is </p>

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

<p>But it doesn't show anything and no errors as well (dev mode enabled).</p>

<p>The idea is make a dynamic sidebar and define which widgets I'd like to see in each template.</p>

<p>This is what I use right now.</p>

<pre><code>        {% set widgets = {
            'about'     : true,
            'instagram' : true,
            'menu'      : false,
            'recipes'   : true,
            'subscribe' : true
        } %}

        {% include "_partials/sidebar" with {
            widgets: widgets
        } %}
</code></pre>

<p>sidebar.html</p>

<pre><code>       {% if widgets.menu == 'true' %}
           content
       {% endif %}
</code></pre>

<p>is there any other more flexible approaches for this?</p>

CC BY-SA 3.0
2017-05-05T18:56:45.023Z
I've personally never found a good reason to use `embed`. It's a strange tag... I use `extends` and `include` 100% of the time.
Lindsey D
<embed>
Trouble with Twig `embed` tag
# Trouble with Twig `embed` tag

(Asked by: username_0 on 2017-05-05)

I'm trying to embed the sidebar and define which blocks to display.
{% embed "_partials/sidebar" %}
    {% block instagram %}{% endblock %}
    {% block subscribe %}{% endblock %}
{% endembed %}

sidebar.html is 
{% block subscribe %}
    block content
{% endblock %}

But it doesn't show anything and no errors as well (dev mode enabled).
The idea is make a dynamic sidebar and define which widgets I'd like to see in each template.
This is what I use right now.
        {% set widgets = {
            'about'     : true,
            'instagram' : true,
            'menu'      : false,
            'recipes'   : true,
            'subscribe' : true
        } %}

        {% include "_partials/sidebar" with {
            widgets: widgets
        } %}

sidebar.html
       {% if widgets.menu == 'true' %}
           content
       {% endif %}

is there any other more flexible approaches for this?

**Tags:** embed

> **Comments:**
> **username_1**: I've personally never found a good reason to use `embed`. It's a strange tag... I use `extends` and `include` 100% of the time.  

---

## 1 answers

### Answer by username_2 on 2017-05-05. Score: 2

I'm going to assume that, as per the use cases in the documentation, embed is a good fit for your requirements.
If you're not sure, extends and include are probably a better choice, as they're much easier to understand and work with.
Moving on, in your example you appear to have confused the roles of the template being embedded, and the template doing the embedding.
Here's how it should look:
{# Page (doing the embedding) #}
{% embed "_partials/sidebar" %}
    {% block subscribe %}
        The custom subscribe block content.
    {% endblock %}
{% endembed %}

{# Embed (being embedded) #}

    
        {% block subscribe %}
            The (optional) default subscribe block content.
        {% endblock %}


---

