Skip to content

Instantly share code, notes, and snippets.

What would you like to do?

thamas 4 hours ago

In Emulsify 04-templates/_default.twig defines twig blocks for page sections » 05-pages/_page.twig adds content (drupal regions) to these sections » templates/product/page--product.html.twig can’t modify these twig blocks because it is not a child but a grandchild of _default. Any solution to this? (I’ve just added the needed part to _page.twig within an if and set it to true in page--product.htm.twig but I do not like to pollute the general page template with a component which is not needed on every page…

evanmwillhite 2 hours ago

there is a solution. It was a little bit to wrap my head around, but I use it a lot now. You can set the block in the middle template like so:

    {% set whatever_content %}
      {% block new_block %}
      {% endblock %}
    {% endset %}

    {% embed "@molecules/whatever.twig" %}
      {% block whatever_block %}
        {{ whatever_content }}
      {% endblock %}
    {% endembed %}

evanmwillhite 2 hours ago

{% block whatever_block %} is the original block from the parent file. {% block new_block %} is the new block that the grandchild can use

h/t to @bjlewis2 for this one

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment