user2268997
user2268997

Reputation: 1391

twig: Overriding blocks defined in embed tag

Is there a way to override blocks defined inside and embed tag inside the parent template in a child template.e.g: I have three templates: a, b and c. a embeds b and c extends a.

{# a.html.twig #}
{% embed b.html.twig %}
  {% block content %}
    laksjflkj
    {% block placeholder %}
    I want to override this template in c, it is actually defined here and has nothing to do with b
    {% endblock placeholder %}
  {% endblock content %}
{% endembed %}

{# b.html.twig #}
{% block content %}
  blahblah
{% endblock %}

{# c.html.twig #}
{% extends 'a.html.twig' %}
  {% block placeholder %}
    let's override the block defined inside a
  {% endblock placeholder %}

How do I override the placeholder block inside c.html.twig?

Upvotes: 2

Views: 744

Answers (1)

Raphaël Vigée
Raphaël Vigée

Reputation: 2045

You have to create a new file called d.html.twig, which extends c.html.twig and override your placeholder block like this :

{# d.html.twig #}
{% extends 'c.html.twig' %}
  {% block placeholder %}
    Overrided !
  {% endblock placeholder %}

Upvotes: 2

Related Questions