在其他模板中包含django模板,以便实际解析它们

时间:2012-02-18 10:29:58

标签: django django-templates

Django的继承结构让我发疯。

我正在创建几个皮肤,每个皮肤都有两列和三列布局:

site1
  - two_cols.html
  - three_cols.html
site2
  - two_cols.html
  - three_cols.html

three_cols.html布局扩展了two_cols.html,只需在布局中添加一个额外的列,并为内容添加额外的django-cms占位符。

对于site1和site2,这个阶段的唯一变化几乎是不同的样式表名称,因此我想将two_cols.html和three_cols.html移动到'common'目录中,只需将site1和site2下的那些更改为它们。

所以:

  • two_cols.html设置CSS路径的块名称
  • three_cols.html扩展了two_cols.html并提供了一个额外的列

我为两个col布局做了这个,它工作正常。但是,对于site1中的three_col布局,例如,我想扩展site1 / two_cols.html(设置CSS路径),然后只包含'common / three_cols.html'(定义额外列)的内容。 / p>

这对我不起作用,因为three_cols.html包含django-cms占位符标签,因为我只是'包含'模板,显然没有被解析,只是被评估。

换句话说,我希望site1 / two_cols.html中的一些设置能够从site1 / three_cols.html中使用,它们都扩展了不同的模板。

摘要

我的问题是如何包含某些东西,就好像它在父模板中一样(django docs说包括不会这样做:https://docs.djangoproject.com/en/1.3/ref/templates/builtins/#include)?

1 个答案:

答案 0 :(得分:1)

为什么不能用正常extends执行此操作? three_cols可以扩展two_cols并在主要块中添加另一列,使用block.super呈现原始的两列。