I'm relatively new to jinja2 (and by no means a web dev expert), and I'm having trouble getting the javascript associated with a jinja template to reload (and update its variables) based on changes in the state of the program.
Essentially, I have one template iterating through a list of items:
{% for item in items %}
<p> {{item['property a']}}</p>
blah blah blah`
and then I call another template I've imported within that for loop:
{% import 'secondTemplate.html' as s %} //not sure whether this matters if it goes inside or outside the for loop
<p> {{s.doSecondStuff(item)}}</p>
That all works. The second template executes each time with each item, which is want I want.
But, I have some secondTemplate.js associated with secondTemplate.html that operates on the variables passed to secondTemplate.html. My problem is that secondTemplate.js only ever operates on the first item's values.
It seemed like the top answer from Loading external script with jinja2 template directive would work, so I've been trying to put the following in the for loop:
{% block javascript %}
<script type="text/javascript">
{% include "secondTemplate.js" %}
</script>
{% endblock %}
But the js is still only reflecting the values of the first item in the list.
Any ideas? Thanks!