How to concatenate strings in django templates?

Ahsan picture Ahsan · Dec 8, 2010 · Viewed 132.5k times · Source

I want to concatenate a string in a Django template tag, like:

{% extend shop/shop_name/base.html %}

Here shop_name is my variable and I want to concatenate this with rest of path.

Suppose I have shop_name=example.com and I want result to extend shop/example.com/base.html.

Answer

Steven picture Steven · Dec 24, 2010

Use with:

{% with "shop/"|add:shop_name|add:"/base.html" as template %}
{% include template %}
{% endwith %}