Ok, my apologies - my idea was close but flawed.
Making a chunk call right in the snippet parameters can be useful, but in this case, the chunk you’re calling is going to inherit the template variables of the homepage, not the page that Ditto is grabbing for you.
So back to referring to a Chunk by name in the Ditto call...
[[Ditto? &tpl=`frontpagefigure-outer` ... ]]
Then Ditto will call that Chunk in the context of the page (article) it’s ditto-ing for you.
The Chunk can stay basically the same, except that
- the custom snippet’s name will now be confusing so I’m renaming it
- we have access to the template variables of the ditto’d document with Ditto’s convention [+tvWhatever+]
[[FrontPageTemplate? &Graph-image=`[+tvGraph-image+]` &Graph-datasource=`[+tvGraph-datasource+]` &Photo=`[+tvPhoto+]` &Mug3=`[+tvMug3+]` &Mug-caption3=`[+tvMug-caption3+]` &Mug2=`[+tvMug2+]` &Mug-caption2=`[+tvMug-caption2+]` &Mug=`[+tvMug+]` &Mug-caption=`[+tvMug-caption+]` &pullquote=`[+tvpullquote+]` ]]
Now we finally have a snippet being called and it will have access to all of the variables that you want it to.
The snippet is going to change - instead of returning the name of the chunk you decide is best based on the variables in the article, we’ll return the chunk itself. And, because I’m not sure whether Ditto, PHx or the MODx parser itself would end up doing the placeholder replacement on the final template chunk, we’ll do that ourselves in the snippet.
<?php
// array of values for replacing in whatever homepage template chunk
$aReplacements = array(
'Graph-image' => $Graph-image,
'Graph-datasource' => $Graph-datasource,
'Photo' => $Photo,
'Mug3' => $Mug3,
'Mug-caption3' => $Mug-caption3,
'Mug2' => $Mug2,
'Mug-caption2' => $Mug-caption2,
'Mug' => $Mug,
'Mug-caption' => $Mug-caption,
'pullquote' => $pullquote
);
$chunkToReturn = '';
// the following logic is bogus - just means to show how you can now access the articles tvs in php to craft the logic
if( $Graph-image != '' && $Mug2 == '' ) {
$chunkToReturn = 'chunk1';
} elseif( $Graph-image == '' && $pullquote != '' ) {
$chunkToReturn = 'chunk1';
}
return $modx->parseChunk($chunkToReturn, $aReplacements, '[+', '+]');
That last line simultaneously parses the chunk and returns it.
In your 6 end chunk templates, you can use the placeholder syntax [+somePlaceholder+] (that’s what the last 2 parameters of the parseChunk method are setting)
I hope this works.