1

假设我有这个结构:

{# base.html #}
{% block content %}{% endblock %}

{# page.html #}
{% extends "base.html" %}
{% block content %}
{% include "snippet.html" %}
{# and I also want somehow to redefine {% block snippet_content %} of snippet here #}
{% endblock %}

{# snippet.html #}
<bells_and_whistles>
    {% block snippet_content %}{% endblock %}
</bells_and_whistles>

我希望代码是不言自明的。

有没有一种优雅的方式来实现这一目标?

4

1 回答 1

1

恐怕这不可能以您想要的方式进行。

您的选择是:

  1. 创建一个modified_snippet.html继承snippet.html并覆盖该块并包含它
  2. 将您的snippet_content块更改为{{ snippet_content }}变量并使用{% include "snippet.html" with snippet_content="My content" %}. 当然,这种方法是相当有限的。
于 2013-05-07T12:21:23.310 回答