I'm busy with an other project, and need to be able to say;
if id=1 then load chunk main-home
if id=4 then load chunk main-gallery
else = chunk main-standard
But main-home has also some ditto call into it, this doesn't work.
So I can probably use a phx:modifier which allows dittocalls into it?!
https://github.com/Jako/PHx-Modifier
But how do I use it?
I think I did do one some time ago but can't remember how I did it and on what project.
Documentation says:
[+string:switch=`xx:{{Chunk}}|yy:[*DocVar*]|default:[+TemplateVar+]+]
I have paste the snippet code and called the snippet switch but doesn't work:
[+string:switch=`1:{{main-home}}|4:{{main-gallery}}|default:{{main-standard}}+]
Anyone can point me in right direction?
Can't load a snippet into a snippet
####EDIT####
I guess it does work when I call my Ditto uncached!
For peoples who might want to use this:
My call:
[!main-switch?
&parent_ids=`1,4`
&chunk_names=`main-home,main-pizza`
&def_chunk_name=`main-default`
!]
My snippet:
<?php
// set the default ids of the top level parent containers
$default_parent_ids = array();
// set the default names of the chunks to display
// based on the same order as the $parent_ids
$default_chunk_names = array();
// set the overall default chunk name
$default_chunk_name = isset($def_chunk_name) ? $def_chunk_name : '';
// ===== end setup ===== //
$parent_ids = isset($parent_ids) ? explode(',',$parent_ids) : $default_parent_ids;
$chunk_names = isset($chunk_names) ? explode(',',$chunk_names) : $default_chunk_names;
if(count($parent_ids) > 0 && count($chunk_names) > 0){
$uparent = $modx->runSnippet('UltimateParent');
$check_array = array($modx->documentObject['id'],$modx->documentObject['parent'],$uparent);
for($x=0; $x < count($parent_ids); $x++){
if(in_array($parent_ids[$x],$check_array)){
$print_chunk = $chunk_names[$x];
}
}
// if $print_chunk is empty set to overall default
if($print_chunk ==''){
$print_chunk = $default_chunk_name;
}
}
return $modx->getChunk($print_chunk);
?>
Main-home chunk has this dittocall:
[[Ditto?
&parents=`9`
&total=`3`
&showPublishedOnly=`1`
&orderBy=`menuindex ASC`
&noResults=`No news..`
&tpl=`news-ditto`
]]
[ed. note: fourroses666 last edited this post 11 years, 4 months ago.]