Last active
August 29, 2015 14:04
-
-
Save bartholomej/81a9df4c73bed66d7ae7 to your computer and use it in GitHub Desktop.
get html class for navigation (multi-level) [MODX Revo]
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
<? | |
/** | |
* 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