Send variable along within include block

html css django

43 просмотра

1 ответ

40 Репутация автора

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 a 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 a {%include "" %} block that replaces/adds to the <p> tags at the end of the marquee code?

(e.g. {% include "marquee.html" {{ stringToDisplay }} %} )

Автор: Dutchman Источник Размещён: 18.07.2016 12:58

Ответы (1)


2 плюса

546 Репутация автора

Решение

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 marquee.html template

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

The include documentation is here

Автор: Chamindu Размещён: 18.07.2016 01:03
Вопросы из категории :
32x32