Using bootstrap to include modal within dynamic php loop. Working wonderfully by dynamically changing the div ID by adding a unique field from each line in the iteration:
foreach($classes as $class => $details)
{
$unique = $class->['ID'];
$name = $class->['Name';
$description = $class->['Description';
?>
<button class="btn btn-xs" data-toggle="modal" data-target="#myModal<?php echo $sclassid ?>">
<?php echo $name ?></button>
<!-- Small modal -->
<div id="myModal<?php echo $sclassid ?>" class='modal fade bs-example-modal-sm' tabindex='-1' role='dialog' aria-labelledby='mySmallModalLabel' aria-hidden='true'>
<div class='modal-dialog modal-sm'>
<div class='modal-content'>
<?php echo $classDescription?>
<button type="button" class="btn btn-xs" data-dismiss="modal">Close</button>
</div>
</div>
</div>
If you're not generating unique IDs (#myModal-somevalue) then every instance of the modal will open up on each click. Ouch.
At any rate - I could style the buttons to look like links, but is there a way to send the same information to the bootstrap jscript code using a link similar to this:
<a href="javascript:void(0)" class="md-trigger" onclick="$('.bs-example-modal-sm').modal('show')"><?php echo $className ?>
Adding data-target="#myModal<?php echo $sclassid ?>"
didn't work.
Is there any reason that one way or the other would be better.
I look forward to your insights and feedback.
Off to read Eloquent Javascript by Marijn Haverbeke...