Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

django template tag pass as parameter of another template tag

Is there a way to pass the result of a template tag to another template tag?

I have 2 custom template tag as following:

@register.simple_tag
def foo():
    return foo_value

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

and I want to to use them in my template like this:

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

I also use {% with %} block but failed.

like image 624
Alireza Saremi Avatar asked Nov 17 '25 03:11

Alireza Saremi


1 Answers

Yes, you can use an as expression part in a template tag to store the result in a variable. For example:

{% load my_custom_tags %}
{% foo as foo_result %}
{% bar foo_result %}
like image 151
Willem Van Onsem Avatar answered Nov 19 '25 20:11

Willem Van Onsem