Skip to content

Instantly share code, notes, and snippets.

@sonicpunk
Created May 29, 2013 14:17
Show Gist options
  • Save sonicpunk/5670598 to your computer and use it in GitHub Desktop.
Save sonicpunk/5670598 to your computer and use it in GitHub Desktop.
MODX snippet. It checks if the resource has siblings and outputs two different classes onto an HTML element such as a div
//[[haveSiblings? &classtwo=`no_sub_menu` &classone=`with_sub_menu`]]
<?php
if(!isset($modx)) return '';
/* setup vars */
$exclude = !empty($exclude) ? (is_array($exclude) ? $exclude : explode(',', str_replace(' ', '', $exclude))) : null;
$id = $modx->resource->get('id');
if(!is_null($exclude) && in_array($id, $exclude)) return '';
$output = '';
$parents = $modx->getParentIds($id);
$parentCount = count($parents);
$parent = array_shift($parents);
$childCount = count($modx->getChildIds($id));
/* get submenu */
if($parentCount > 1 || $childCount > 0)
{
if($parentCount > 1 && $childCount > 0)
{
$output .= $classone;
}
elseif($parentCount > 1 && $childCount == 0)
{
$output .= $classone;
}
elseif($parentCount == 1 && $childCount > 1)
{
$output .= $classone;
}
}
else{
$output .=$classtwo;
}
return $output;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment