【问题标题】:django template tag pass as parameter of another template tagdjango 模板标签作为另一个模板标签的参数传递
【发布时间】:2019-08-07 11:39:15
【问题描述】:

有没有办法将模板标签的结果传递给另一个模板标签?

我有 2 个自定义模板标签如下:

@register.simple_tag
def foo():
    return foo_value

@register.simple_tag
def bar(value):
    return bar_value + value

我想像这样在我的模板中使用它们:

{% load my_custom_tags %}
{% bar foo %}

我也使用{% with %} 块但失败了。

【问题讨论】:

    标签: django django-templates templatetags


    【解决方案1】:

    是的,您可以在模板标签中使用as 表达式部分将结果存储在变量中。例如:

    {% load my_custom_tags %}
    {% foo as foo_result %}
    {% bar foo_result %}

    【讨论】:

      猜你喜欢
      • 2013-11-21
      • 2017-08-11
      • 2021-06-05
      • 2021-09-04
      • 2016-12-25
      • 1970-01-01
      • 2011-08-18
      • 2021-02-15
      • 2011-02-09
      相关资源
      最近更新 更多