50

I cannot do the following in Django:

{% include "admin/includes/pager.html" with title_pager="{{myobject.title}}" %}

or

{% include "admin/includes/pager.html" with title_pager="{{myobject}}" %}

What is the workaround?

Matthew Rankin
  • 457,139
  • 39
  • 126
  • 163
gpasse
  • 4,380
  • 7
  • 44
  • 75

1 Answers1

121

You do not need to surround arguments in {{ }} brackets in template tags.

If it's a variable, not a string, then do not use "" quotes.

The following should work:

{% include "admin/includes/pager.html" with title_pager=myobject.title %}

{% include "admin/includes/pager.html" with title_pager=myobject %}

See the Django docs for the include tag for more information.

Alasdair
  • 298,606
  • 55
  • 578
  • 516
  • 4
    @Bwire The [`include`](https://docs.djangoproject.com/en/1.6/ref/templates/builtins/#include) docs give an example with multiple variables. If you're still stuck after reading that, please open a new question. – Alasdair Apr 06 '14 at 20:33
  • 9
    [Updated link](https://docs.djangoproject.com/en/2.0/ref/templates/builtins/#include) and answer: `{% include "name_snippet.html" with person="Jane" greeting="Hello" %}` – Richard Apr 27 '18 at 23:02
  • 1
    My template wasn't rendering, and I found that the reason was that I had it split over multiple lines, to make it more readable. But I needed `{%include "bla.html" with var=value %}` in a single line. – Michele Piccolini Mar 10 '21 at 13:26