Skip to content

Instantly share code, notes, and snippets.

@gebeer
Created April 6, 2015 04:35
Show Gist options
  • Save gebeer/aa9fa32b2d01b05697c9 to your computer and use it in GitHub Desktop.
Save gebeer/aa9fa32b2d01b05697c9 to your computer and use it in GitHub Desktop.
Function to render Bootstrap 3 Accordion markup from a ProcessWire PageArray
/*render a Bootstrap 3 accordion from a PW PageArray
variables passed to this function
$pages: PageArray the children of which will be rendered into an accordion
$title: string, name of the field to be used as panel title, eg "title"
$content: string, name of the field to be used as panel content, eg "bodycopy"
$accordion = "<div class='panel-group' id='accordion' role='tablist' aria-multiselectable='true'>";
*/
function bs3AccordionMarkup($pages, $titlefield, $contentfield) {
$accordion = "<div class='panel-group' id='accordion' role='tablist' aria-multiselectable='true'>";
$i = 1;
foreach ($pages as $child) {
$in = ($i == 1) ? " in" : "";
$collapsed = ($i != 1) ? " class='collapsed'" : "";
$accordion .= " <div class='panel panel-default'>
<div class='panel-heading' role='tab' id='heading$i'>
<h3 class='panel-title'>
<a$collapsed data-toggle='collapse' data-parent='#accordion' href='#collapse$i' aria-expanded='true' aria-controls='collapse$i'>
{$child->$titlefield}
</a>
</h3>
</div>
<div id='collapse$i' class='panel-collapse collapse$in' role='tabpanel' aria-labelledby='heading$i'>
<div class='panel-body'>
{$child->$contentfield}
</div>
</div>
</div>";
$i++;
}
$accordion .= "</div>";
return $accordion;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment