...can’t find it though<?php
// parent ID
$ids="11";
// how many levels deep
$depth="5";
// get all children
$childArray = $modx->getChildIds($ids, $depth);
// get IDs from all children that are containers
$container = $modx->getDocuments($childArray, 1, 0, "id", 'isfolder=1');
// count the IDs and loop through the array
$childrenCount = count($container);
for($x=0; $x<$childrenCount; $x++) {
$folderids .= $container[$x]['id'].",";
}
return $folderids;
?>
unfortunately the other Snippet doesn’t like the output http://modxcms.com/forums/index.php/topic,36667.msg290667.html#msg290667
return implode( ',',$folderids);
return $folderids;
...then it works
// just for my record<?php
/*
* This Snippet will return a comma separated List of container IDs
* within a declared container.
* e.g. [[getChildContainer? &parent=`2` $depth=`2`]]
* btw. "print" to return the value is used because i call the Snippet within
* another Snippet. you can change "print" to "return" if you're not.
*/
// use parent ID if declared, otherwise default to 0 (site root)
$parent=isset($parent) ? $parent : '0';
// how many levels deep. i think it defaults to 10 levels if not set
$depth=isset($depth) ? $depth : '';
// get all children
$childArray = $modx->getChildIds($parent, $depth);
// get IDs from all children that are containers, published and not deleted
$container = $modx->getDocuments($childArray, 1, 0, 'id', 'isfolder=1');
// count the IDs
$childrenCount = count($container);
// loop through the array if there are child containers
if ($childrenCount!==0){
for($x=0; $x<$childrenCount; $x++) {
$folderids .= $container[$x]['id'].",";
}
// within another Snippet use print, instead of return
print $folderids;
} else {
// return empty string if there are no containers
print '';
}
?>
Hi Bob,
thanks
is already returning a comma separated list.return $folderids;
btw. i found out, that if i use that Snippet within the other one ( link above) to return the parent IDs, i need to "print" the result instead of "return"...then it works
About "print"ing the results. That’s weird, I would have expected the opposite.afaik, "print" should be used, too if the Snippet is included as an external file. maybe there’s a connection.
"print" should be used, too if the Snippet is included as an external fileFWIW,I like to use the following setup and it normally works pretty well.
<?php $output =''; include MODX_BASE_PATH.'assets/snippets/testsnippet/test_processor.php'; return $output; ?>
<?php
defined('IN_PARSER_MODE') or die('<b>UNAUTHORIZED_ACCESS_ERROR</b>');
// add whatever you want to the $output
$output .='<p>Just a test message</p>';
?>