Skip to content

Instantly share code, notes, and snippets.

@Mark-H
Created May 9, 2011 13:14
Show Gist options
  • Save Mark-H/962492 to your computer and use it in GitHub Desktop.
Save Mark-H/962492 to your computer and use it in GitHub Desktop.
Simple snippet (output filter) for MODX Revolution related items. Call as [[snippetname? &tpl=`chunkname` &input=`[[*your-comma-delimited-id-tv]]`]]
<?php
if ($input == null) { return 'No relevant items found.'; }
$tpl = $modx->getOption('tpl',$scriptProperties,null);
if (($tpl === null) || (!$modx->getChunk($tpl))) { return 'No template found'; }
$ids = explode (',', $input);
foreach ($ids as $a => $key) {
$document = $modx->getObject('modResource', array(
'published' => 1,
'id' => $key));
if ($document) {
$output[] = $modx->getChunk($tpl,$document->toArray());
}
}
return implode(', ',$output);
?>
@Mark-H
Copy link
Author

Mark-H commented May 9, 2011

Did you select any items in your TV?

What do you get if you just output [[*relatedPages]] in your template or content?

@neilp123
Copy link

neilp123 commented May 9, 2011

Yep, have 4 items selected in the listbox.

When I just call the TV, I get a comma-delimited list of the ids I've chosen.

@neilp123
Copy link

Hi Mark,

I've had a little look at this again this morning.

It seems that part of the snippet is working. When I remove &input, I get the 'No relevant items found' messgae, and when I remove &tpl, I get the 'No template found message.

It just won't display anything when I do include both the input and the template. I've tried altering the template to just display the id, or the pagetitle, but with no luck.

Any thoughts would be much appreciated!

@Mark-H
Copy link
Author

Mark-H commented May 11, 2011

I suspect you mistyped the chunk name.. It worked fine for me.

Updated the gist above with some better error reporting for chunks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment