I'm using Bootstrap 3 to build a tab-panel component, based on information coming from the end-user. I don't like how there's a second foreach loop, but I don't know how else to print the HTML correctly.
Given an array structured like this:
[
{
"title": "Title 1",
"content": "Lorem Ipsum"
},
{
"title": "Title 2",
"content": "Lorem Ipsum"
}
]
And a "view" template structured like this:
<?php $panels = rwmb_meta("ssc_tabpanels") ?>
<?php if( !empty($panels) ): ?>
<div id="program-details">
<ul class="nav nav-pills nav-stacked" role="tablist">
<?php foreach($panels as $i => $p): ?>
<li role="presentation">
<a href="#tab-<?php echo $i ?>" data-toggle="tab"><?php echo $p['title'] ?></a>
</li>
<?php endforeach; ?>
</ul>
<div class="tab-content">
<?php foreach($panels as $i => $p): ?>
<div class="tab-pane" id="tab-<?php echo $i ?>"><?php echo $p['content'] ?></div>
<?php endforeach; ?>
</div>
</div>
<?php endif; ?>
What suggestions do you have for removing the second foreach
loop while still maintaining the correct bootstrap code?