unriale
unriale

Reputation: 59

Pass multiple arguments to a custom filter Django

I have a custom filter that looks like this

register = template.Library()

@register.filter
def makebreadcrumbs(value, arg):
    pass
    

How can I pass multiple arguments to the filter?

  {% with request.resolver_match.namespace as name_space %}
    {{ request.path|makebreadcrumbs:name_space|safe }}
  {% endwith %} 

In the code above makebreadcrumbs is my custom filter, request.path is a variable (value), and name_space is an argument.

Upvotes: 1

Views: 492

Answers (1)

0sVoid
0sVoid

Reputation: 2663

I think what you want is a Django simple tag which can accept multiple arguments:

@register.simple_tag(takes_context=True)
def breadcrumbs(path, name_space):
   # your code
   return ...
{% breadcrumbs request.path request.resolver_match.namespace %}

Upvotes: 2

Related Questions