Skip to content

Instantly share code, notes, and snippets.

@pepebe
Forked from christianseel/Chunk tabNavigationItem
Last active June 6, 2019 10:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pepebe/9ac649f7395bde32ad169077638e147b to your computer and use it in GitHub Desktop.
Save pepebe/9ac649f7395bde32ad169077638e147b to your computer and use it in GitHub Desktop.
"generateTabs" output (Bootstrap 3.x) filter for ContentBlocks. See http://sedadigital.slides.com/sedadigital/contentblocks2#/4/6 for instructions.
<li class="tab-title [[+idx:is=`1`:then=`active`:else=``]]" role="presentational">
<a href="#[[+id]]" role="tab" tabindex="0" aria-selected="false" controls="[[+id]]">[[+title]]</a>
</li>
<div class="tab-accordion-cmp">
<ul class="tabs show-for-large-up" data-tab>
[[+rows:generateTabs]]
</ul>
<dl class="tabs-content accordion" data-accordion>
<dd class="accordion-navigation">
[[+rows]]
</dd>
</dl>
</div>
<a href="#tab-[[+unique_idx]]-[[+idx]]"
class="accordion-tab hide-for-large-up">
[[+title]]
</a>
<section id="tab-[[+unique_idx]]-[[+idx]]"
data-tabcontent data-title="[[+title]]"
role="tabpanel" aria-hidden="false"
class="content [[+idx:is=`1`:then=`active`:else=``]]">
<div class="content-box section-box">
[[+content]]
</div>
</section>
<?php
$doc = new DOMDocument();
$doc->loadHTML('<meta http-equiv="content-type" content="text/html; charset=utf-8">'.$input);
$divs = $doc->getElementsByTagName('section');
$tabs = array();
$idx = 1;
foreach($divs as $div) {
if ($div->hasAttribute('data-tabcontent')) {
$tabs[$div->getAttribute('id')] = $div->getAttribute('data-title');
}
}
$tabheaders = '';
$idx = 1;
foreach($tabs as $id => $title) {
$tabheaders .= $modx->getChunk('tabNavigationItem', array(
'idx' => $idx,
'id' => $id,
'title' => $title
));
$idx++;
}
return $tabheaders;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment