I am using Flask with Jinja2 templates. I have a Jinja2 loop populating a table. I have buttons to collapse/expand a nested table for each row in the outer table.
The way I’ve approached this is to place the hidden table inside of a Jinja2 if statement. However, I have no way to update the variable that the if statement calls. I couldn’t use JavaScript since it is inside a Jinja2 loop.
Is there a way to update a variable on a button click inside a Jinja2 loop? Or a way to change HTML attributes (style visibility and hidden)?
HTML:
{% for row in table %}
<tr>
<td>
<button>
<!—- Click button to toggle row.visible —>
</button>
</td>
</tr>
{% if row.visible %}
<tr>
<td>
<table>
<!—- Hidden table -—>
</table>
</td>
</tr>
{% endif %}
{% endfor %}