Using Symfony2, TWIG and Bootstrap, I would like to to display modal windows (as described here).
But I want to load the content of these modal only if the user click on the button to display it, not at the main page's loading.
Context: I have a list of elements on my main page, and I would like to give the possibility to the user to have more information about some particular elements (one at a time). So the user clicks on the element, the modal shows up and details appear. As there are quite a lot of elements and the detailled info are quite heavy to load, I want to load only the necessary ones, on demand.
I know and already use (for other things) TWIG's {% include ... %}
,{% embed ... %}
and {% render ... %}
, I know how to display a TB Modal but I didn't find the way to do what I want :(
[EDIT] SOLUTION
For later reference. @Syjin's answer put me on the track but some additional details might be useful :-D
In the main Twig page, the one with the list:
<a data-toggle="modal" href="{{ path('MyBundle_MyEntity_seeModal', {'entity_id': entity.id}) }}" data-target="#myModal">Click me</a>
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
</div>
Create a new Twig template seeModal.html.twig
with the content of the modal, as described in the doc:
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4 class="modal-title" id="myModalLabel">Modal title</h4>
</div>
<div class="modal-body">
...
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary">Save changes</button>
</div>
</div>
</div>
Create the related route and Controller's action.