Search code examples
htmljqueryjinja2

change inija2 template file with jquery or javascript


I have no idea how, but would like to know if it is possible to change the file in the jinja2 include statement.

such as: {% include file.name %} to {% include file1.name %}

Since the file.name is in include parentheses, I could not use {{ file.name }} to achieve this.

Thought maybe I could use something like jquery,

$(".btnt").click(function(){
    $("section:fourth").replaceWith("{% include 'file1.name' %}");}

maybe initiate with button click, would this have to be on same page. I tend to use flask python for most projects.


Solution

  • Actually used jinja2 to read variable to decide which file.name to use

    {% if var %}
    {% include file.name %}
    {% else %}
    {% include file1.name %}
    {% endif %}
    

    This checks var for true, set from flask render template arguments. If true uses file.name, if false uses file1.name