twig:覆盖嵌入标记中定义的块

时间:2015-07-12 10:14:09

标签: twig

是否有办法覆盖子模板中父模板内部和embed标签内定义的块.eg:我有三个模板:ab和{{1 }}。 c嵌入ab扩展c

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 %} 内的placeholder块?

1 个答案:

答案 0 :(得分:1)

您必须创建一个名为d.html.twig的新文件,该文件会扩展c.html.twig并覆盖您的placeholder块,如下所示:

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