Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django: cannot pass variable to included template?

I got a problem where I want to use template including in Django.

Here is the real example: I got 3 files:

  • home.html (will get the context variable passed from Views)
  • base.html (the skeleton template file)
  • and the header.html (included by base.html).

If I put the code below directly in base.html without including header.html, the {{title}} variable passed from home is correctly called. But if I include the header.html in base.html, the {{title}} variable's value cannot be called.

<title>{% block title %}{% endblock %} | {{ SITE_INFO_TITLE }}</title>

Is there any solution to this problem? Thanks.

like image 944
duy Avatar asked Dec 26 '10 10:12

duy


1 Answers

Could you just pass in a variable within the {% include %} tag? It's documented here: https://docs.djangoproject.com/en/1.5/ref/templates/builtins/#include

{% include "name_snippet.html" with person="Jane" greeting="Hello" %}
like image 111
The Pied Pipes Avatar answered Sep 23 '22 19:09

The Pied Pipes