Discovering the world of Django template language has been quite an interesting journey for me, especially as I experiment with bootstrap collapses to showcase my items. Let's take a look at the code snippet below:
{% for item in items %}
<div id="accordion">
<div class="card">
<div class="card-header" id="headingOne">
<h5 class="mb-0">
<button class="btn btn-link" data-toggle="collapse" data-target="#collapseOne" aria-expanded="true" aria-controls="collapseOne">
{{item.item_name}}
</button>
</h5>
</div>
<div id="collapseOne" class="collapse show" aria-labelledby="headingOne" data-parent="#accordion">
<div class="card-body">
{{item.description}}
</div>
</div>
</div>
</div>
{% endfor %}
This particular implementation is based on the collapse feature within Bootstrap documentation which can be found here. However, a challenge arises when all items have the same id 'collapseOne'. Consequently, clicking on any item triggers the collapsing or expanding of every item on display. I did try using
id="collapse{{item.item_name}}"
without much success. Is there a way to dynamically pass variables into the div ID attribute?