Jamgreen
Jamgreen

Reputation: 11069

Include with url variable in Django template

I have a "create new object" button in a template file. I want to include the button in several places at my website, but I want to include the template with a link. I've tried:

{% include "snippets/icon_add.html" with link="/create_new_item/" only %}

But I want to use the benefits of {% url 'create_new_item' %}. Can I do something like:

{% include "snippets/icon_add.html" with link={% url 'create_new_item' %} only %}

Upvotes: 8

Views: 5780

Answers (1)

Joseph Victor Zammit
Joseph Victor Zammit

Reputation: 15320

Try with {% url ... as var %} syntax. Example:

{% url 'create_new_item' as the_url %}
{% include "snippets/icon_add.html" with link=the_url %}

Docs link here.

Upvotes: 27

Related Questions