1

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?

1
  • 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.
    – Lindsey D
    Commented May 5, 2017 at 18:56

1 Answer 1

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) #}
<div class="sidebar">
    <div class="sidebar__subscribe">
        {% block subscribe %}
            The (optional) default subscribe block content.
        {% endblock %}
    </div>
</div>
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.