Maybe something like this? Note the ditto params are at the bottom of the snippet, modify as needed.
<?php
/* hierarchy_based_chunk
[!hierarchy_based_chunk?
&ids_chunks=`2|hbc_1 , 21|hbc_2`
&def_chunk=`hbc_def`
!]
the above snippet call in a template produces:
hbc_1 chunk on doc 2 and all children/grandchildren
hbc_2 chunk on doc 21 and all its children/grandchildren
hbc_def chunk on all other documents
*/
//$xstart = $modx->getMicroTime();
// set default parent id | chunk name
// ex: $default_ids_chunks = array( '2|hbc_1' , '21|hbc_2' );
$default_ids_chunks = array();
// set an overall default chunk name
$default_chunk = isset( $def_chunk ) ? $def_chunk : '';
$output ='';
$print_chunk ='';
$parts = $ids_chunks !='' ? explode( ',', $ids_chunks ) : $default_ids_chunks;
if( !empty( $parts ) ){
$uparent = $modx->runSnippet( 'UltimateParent' );
$check_array = array( $modx->documentObject['id'], $uparent );
foreach( $parts as $k => $v ){
$xplod = explode( '|', $v );
// id
$x = trim( $xplod[0] );
// chunk name
$y = trim( $xplod[1] );
if( in_array( intval( $x ), $check_array ) && $print_chunk =='' ){
$print_chunk = $y;
}
}
}
// if $print_chunk is empty set to overall default
if( $print_chunk =='' ){
$print_chunk = $default_chunk;
}
// set up the ditto snippet params
$ditto_params = array(
'parents' => '5',
'total' => '99',
'showPublishedOnly' => '1',
'orderBy' => 'menuindex ASC',
'tpl' => $modx->getChunk( $print_chunk ),
);
// process the ditto snippet
$output .= $modx->runSnippet( 'Ditto', $ditto_params );
//$xend = $modx->getMicroTime();
//$output .='<p>'.( str_replace( '-', '', sprintf( "%2.4f s", $xstart - $xend ) ) ).'</p>';
return $output;
?>
Thanks Breezer
Evolution user, I like the back-end speed and simplicity
