I want to pass a variable inside an include
statement:
init.py:
@app.route("/about")
def about():
return render_template("index.html", content="about.html")
index.html:
{% include {{ content }} %}
does not work!
I want to pass a variable inside an include
statement:
init.py:
@app.route("/about")
def about():
return render_template("index.html", content="about.html")
index.html:
{% include {{ content }} %}
does not work!
As this thread pops up via the google search and the answer is pretty straight forward:
Just do not use the {{}}
syntax inside the include statement. So instead of
{% include {{ content }} %}
use
{% include content %}
which will evaluate the variable set in render_template
This question has already been asked and answered.
How to pass selected, named arguments to Jinja2's include context?
Use utility processor to pass in variables to your template.
With the following code, foo will be defined and available to all of your templates.
@app.context_processor
def utility_processor():
rval = dict()
rval['foo'] = 'bar'