ADDED TO REPOSITORY
This is a snippet to output a certain string or chunk when it meets certain criteria, such as the current document id is listed on $id parameter, or the current document parent id is listed on $parent parameter. It can react to $notid or $notparent parameter as well, which is the opposite from the previous example.
I use this a lot when I use @INHERIT binding on some of my TV. With this snippet, I can determined on which document level the output has to be parsed and so on. Hope you guys might find it useful.
Sincerely,
Wendy Novianto
DJAMOER
<?php
/**
* CurrDocOut
* Outputing a desired output from string being passed from parameters or
* from chunk name depending on the ID to be included or excluded. It will
* output nothing if all the condition was not matched.
*
* Parameters:
* - $id - Documents ID separated with comma to be included
* - $notid - Documents ID separated with comma to be excluded
* - $parent - Parent ID separated with comma to be included
* - $notparent - Parent ID separated with comma to be excluded
* - $out - String to be outputed, don't use it together with $outChunk parameter
* - $outChunk - Chunk name to be outputed, don't use it together with $out parameter
*/
print_r($modx->documentListing);
// Parse $id parameter
if(isset($id)) {
$tempid = split(',', $id);
$id = array();
foreach($tempid as $v) {
if(is_numeric($v)) $id[] = (int) $v;
}
}
else $id = array();
// Parse $notid parameter
if(isset($notid)) {
$tempid = split(',', $notid);
$notid = array();
foreach($tempid as $v) {
if(is_numeric($v)) $notid[] = (int) $v;
}
}
else $notid = array();
// Parse $parent parameter
if(isset($parent)) {
$tempid = split(',', $parent);
$parent = array();
foreach($tempid as $v) {
if(is_numeric($v)) $parent[] = (int) $v;
}
}
else $parent = array();
// Parse $notparent parameter
if(isset($notparent)) {
$tempid = split(',', $notparent);
$notparent = array();
foreach($tempid as $v) {
if(is_numeric($v)) $notparent[] = (int) $v;
}
}
else $notparent = array();
// Count $id & $notid array
$idsum = count($id);
$notidsum = count($notid);
$parentsum = count($parent);
$notparentsum = count($notparent);
// Outputing the right content
$output = '';
$condition = true;
if($idsum > 0) $condition = $condition && in_array($modx->documentIdentifier, $id);
if($notidsum > 0) $condition = $condition && !in_array($modx->documentIdentifier, $notid);
if($parentsum > 0) $condition = $condition && in_array($modx->documentObject['parent'], $parent);
if($notparentsum > 0) $condition = $condition && !in_array($modx->documentObject['parent'], $notparent);
if($condition) {
if(isset($out) && trim($out) != '') $output .= $out;
if(isset($outChunk) && trim($outChunk) != '') $output .= $modx->getChunk($outChunk);
}
// Return output string
return $output;
?>