I was struggling with the fact that the parser can not pars a snippet insite a chunk call, e.g. {{chunkname-[[snippetname]]}}.
You may ask why would you want to do somthing like that? Here is why:
I often make multilangual sites and to show the visitor on what language he is I use flags those flags also have a link to the other languages.
so using a snippet like UltimateParent inste a chunk call would give me the option to get ID specific chunk calls like this {{flags-[[UltimateParent]], this than generates a chunk call like this {{flags-12}} (if the ultimateParent is 12 for that language) but as I sayd befor this does not work.
Now I’v adapted Susan’s great Script (UlimateParent) to ouput a chunk call based on the UltimateParent ID:
Just call the snippet like this:
[!GetChunkByUPID? &chunk=`chunkprefix-`!]
and create the coresponding chunks e.g. chunkprefix-12
when you do not set the $chunk in the snippet call or in the snippet itself it will return a chunkname that only contains a ID e.g. {{12}}
this way you can display chunks that correspond to UltimateParents ID without using a TV and @INHERIT
// GetChunkByUPID - MODx snippet (Get Chunk by UltimateParent ID)
// recursively searches the document tree
// and determines the "ultimate" parent
// (the one whose parent is 0)
// of the given document, then ads that ID to a chunk name.
// it will then give you a chunk call corresponding to the id
// e.g. if $chunk is "flags-" and the id that is found is "12" it will give you a chunk call : {{flags-12}}
// this way you can display chunks that correspond to UltimateParents ID without using a TV and @inherit
//
// created 02 Nov 2005 by [email protected]
// adapted 19 June 2006 by [email protected]
//
// released to the public domain
//
//
//
//settings:
//set the chunk prefix eg "flags-" here or
//use it in the call like this: [!GetChunkByUPID? &chunk=`chunkprefix`!]
//
$chunk = (isset($chunk))? $chunk : "";
//
//The rest will take care of it self
//
$id = $modx->documentIdentifier;
$pid = $modx->getParent($id,1,"id");
if($pid['id'] == 0) { return $id; }
while ($pid['id'] != 0) {
$id = $pid['id'];
$pid = $modx->getParent($id,1,"id");
}
$output= "{{".$chunk.$id."}}";
return $output;
Greets Dimmy