Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

onclick load {% include 'test.html' %}

I would like to load Jinja2 templating string when user clicks on an element. for example I have tags like:

 <div class="one"><a href="#one">One</a></div>
 <div class="two"><a href="#two">Two</a></div>
 <div class="three"><a href="#three">Three</a></div>

only after clicking on One, I must load the bellow string:

{% include 'one.html' %}

and after clicking on Two, this string must be loaded:

{% include 'two.html' %}

and so on. How can I manage this issue? Dynamic content loading when clicking

like image 203
Max Avatar asked May 19 '26 12:05

Max


2 Answers

Keep in mind that JavaScript happens in the browser (client-side), while Jinja2 is python-based templating which will occur server-side. Showing the template string via JavaScript will not achieve your desired result. There seem to be two ways of achieving what you want.

One option is to output the result of the template when the page loads initially and then display it through some javascript behavior. There are many jQuery plugins to achieve this result, one example you may look at is Bootstrap Tabs.

Another option, if you don't wish to produce all of the template results when you first load the page, would be to load the result of the templates via ajax. The ajax request would need have to be served the result of the desired jinja2 template which can then be output into your page. jQuery's load provides a simple way to do this.

like image 94
Jon Surrell Avatar answered May 21 '26 00:05

Jon Surrell


You will have to use some JavaScript to achieve that.

One solution is to use jQuery load http://api.jquery.com/load/

like image 39
Kamil Pawłowski Avatar answered May 21 '26 01:05

Kamil Pawłowski