I was wondering if anyone would could help me with getting something to check for multiply arrays. I am learning as I go on the the dev part but I hoping for some guidance.
The idea
$tvArray = $modx->getTemplateVarOutput(array(’firstImage’)); Single instance
$image1 = $tvArray[firstImage];
if (empty($image1)){
$output = "";
} // the rest as follows
I have been trying to achieve the following
$tvArray = $modx->getTemplateVarOutput(array(’firstImage’,’secImage’)); Multiply instances
$image1 = $tvArray[firstImage];
$image2 = $tvArray[secImage];
if (empty($image1)){
$output = "";
if (empty($image2)){
$output = "";
else {
$output =’<img src="’.$image1.’" width="380" height="300" />’;
}$output =’<img src="’.$image2.’" width="380" height="300" />’;
I am sure some coders will get the idea of what I am trying to achieve. Not just looking for the exact code but more of this how you achieve and why it works.
Wanting to learn how to develop more these ideas out. Dunce cap firmly seated on my head ready to learn.
I think you might also ba able do it with PHX without any snippet.
Something like this:
[*tv1:ifempty=`[*tv2:ifempty=`[*tv3*]`*]`*]
You’d have to have PHX installed. I think the snippet would be faster.
Hey Bunk, don’t know if you could me on this.
I am trying to use the same script above but hitting a wall- I know why but I don’t know how to get around it.
I am using a ditto call on container [[Ditto? &tpl={{chunk}}]]
Chunk
{{[+pagetitle+] [[SnippetTVArray]]}}
I tried changing getTemplateVarOutput -> getDocumentChildrenTVarOutput. Outputs nothing, after reading the API getDocumentChildrenTVarOutput works but the array uses the ID as the key in the array. Which I am trying to figure out how to merge the arrays - remove the id and make the arrays without keys. Am I crazy???
Since there is no getChildrenTemplateVarOutput....
Any help would be appreciated!
I think I confused the situation.
Here is my snippet that only works on the actual page.
--doc 1 [[Snippet]]
<?php
$output = ’’;
$myArray = $modx->getTemplateVarOutput(array(’tv1’,’tv2’));
if(empty($myArray[’tv1’])){
} else {
$output .= ’ ’.$myArray[’tv1’].’ ’;
}
if(empty($myArray[’tv2’])){
} else {
$output .= ’ ’.$myArray[’tv2’].’ ’;
}
return $output;
?>
What I am trying to achieve.
- Folder 1 - no tv’s (Template 1)
-- doc 1 - tv 1 - tv 2 (Template 2)
-- doc 2 - tv 1 - tv 2 (Template 2)
-Folder 1 [[Ditto? &tpl=`myTpl`]]
If place the [[SnippetAbove]] in myTpl - nothing outputs.
Thank you so much for taking the time!