Dutchman Dutchman - 4 months ago 23
CSS Question

Send variable along within include block

I'm working on a personal Django project where my plan is to make some sort of function in my site in form of a CSS Marquee (scrolling text).

I was able to make an marquee.html file with the code from here, and use it on several pages on my site using {% include "marquee.html" %} blocks, but the displayed string in the marquee is within the html file itself (marquee.html) between < p >-tags

Is there any way to send a variable/string along with an {%include "" %} block that replaces/adds to the < p > tags at the end of the marquee code?

(e.g.

{% include "marquee.html" {{ stringToDisplay }} %}
)

Answer

The current context is available for the included template. You can use the "with" option to send any additional context.

 {% include "marquee.html" with message="Hello" %}

and in your marqueue.html template

<div>{{ message }}</div>

https://docs.djangoproject.com/en/1.9/ref/templates/builtins/#include

Comments