Last active
December 17, 2015 04:58
-
-
Save hagatorn/5554164 to your computer and use it in GitHub Desktop.
Recursive tree style accordion for kirby
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php if(!isset($subpages)) $subpages = $site->pages(); | |
if(!isset($id)) $id = 0; ?> | |
<?php $id+=1; | |
foreach($site->breadcrumb() AS $crumb): | |
$breadcrumb[] = $crumb->url(); | |
endforeach ?> | |
<ul id="accordiongroup_<?php | |
$in = 0; | |
echo $id ?>" class="collapse <?php if ($id==1) {$in=1;}?> | |
<?php | |
foreach ($subpages->visible() AS $sp): | |
if(in_array($sp->url(), $breadcrumb)) {$in=1;} | |
endforeach; | |
if ($in==1) {echo 'in';} | |
?> | |
"> | |
<?php | |
foreach($subpages->visible() AS $p): ?> | |
<?php if($p->hasChildren()){?> | |
<li class="depth-<?php echo $p->depth() ?> parent"> | |
<a href="#accordiongroup_<?php echo $id+1 ?>" data-toggle="collapse" data-parent="<?php echo $id ?>"> <?php echo $p->title() ?></a> | |
<?php snippet('accordionmenu', array('subpages' => $p->children(), 'id' => $id)) ?> | |
<?php $id+=1;} | |
else { ?> | |
<li class="depth-<?php echo $p->depth() ?>"> | |
<div><a class=" <?php echo ($p->isActive()) ? 'active' : '' ?>" href="<?php echo $p->url() ?>"><?php echo $p->title() ?></a></div> | |
<?php } | |
?> | |
</li> | |
<?php endforeach;?> | |
</ul> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment