Skip to content

Instantly share code, notes, and snippets.

@bartholomej
Last active August 29, 2015 14:04
Show Gist options
  • Save bartholomej/81a9df4c73bed66d7ae7 to your computer and use it in GitHub Desktop.
Save bartholomej/81a9df4c73bed66d7ae7 to your computer and use it in GitHub Desktop.
get html class for navigation (multi-level) [MODX Revo]
<?
/**
* getActiveClass: get html class for navigation (multi-level)
*
* PARAMETERS:
* &docid: Document ID
* &class [optional]: custom html class name (default: "active")
* &self [optional]: add class also on self document (default: 1)
*
* EXAMPLES:
* [[getActiveClass? &docid=`[[+id]]`]] // return: class="active"
* [[getActiveClass? &docid=`[[+id]]` &class=`clicked`]] // return: class="clicked"
* [[getActiveClass? &docid=`[[+id]]` &self=`0`]] // return: class="active" (only parents, not self)
*
* AUTHOR:
* Pepim <https://github.com/pepimpepa>
* Bartholomej <https://github.com/bartholomej>
*
*/
$class = isset($class)? $class : "active";
$self = isset($self)? $self : 1;
$output = 'class="'. $class .'"';
$currentId = $modx->resource->get('id');
if($currentId == $docid && $self == 1) {
return $output;
}
$parents = $modx->getParentIds($currentId);
if (in_array($docid, $parents)) {
return $output;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment