0

我的问题基本上是关于渲染变量。例如,假设我有一个对象块,其中 block.text='{{ "hello"|trans }}'

我想将其包含在我的基本模板中。以下显然不适用于我的意图。

{% include block.text %}

我如何将它渲染到我的模板中?

4

1 回答 1

0

It does not seem a good idea generate dynamic templates from view side to render into a template.

But remember do you have other elegant approach like:

  • Inclusion tags Is type of template tag that displays some data by rendering another template.
  • Include "Loads a template and renders it with the current context."

Also, take in mind, that you can use IF statement into a template to include or not include some template and, also, you can pass additional context to the included template using keyword arguments (ex: {% include "name_snippet.html" with person="Jane" greeting="Hello" %} ).

于 2013-04-29T08:23:23.413 回答