Skip to content

Instantly share code, notes, and snippets.

@Mark-H
Created May 9, 2011 13:14
Show Gist options
  • Select an option

  • Save Mark-H/962492 to your computer and use it in GitHub Desktop.

Select an option

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);
?>
@neilp123

neilp123 commented May 9, 2011

Copy link
Copy Markdown

Hi Mark,

Hope its ok to comment here.

Don't seem to be getting any output from what I have so far, which is:

@select pagetitle,id FROM modx_site_content WHERE parent BETWEEN '55' AND '58'

Thats in the TV (called relatedPages), Input Option Values box.

Snippet listMyResources is as above.

Call is: [[listMyResources? &input=relatedPages &tpl=relatedPagesTpl]]

relatedPagesTpl is :

[[+pagetitle]]

That doesn't output anything, so I'm not sure where I might be going wrong :o(

@neilp123

neilp123 commented May 9, 2011

Copy link
Copy Markdown

Oops, looks like some of the code got stripped out! I have used backticks on my snippet call, and the chunk is just a simple hyperlink, linking to the [[~[[*id]]]]

@Mark-H

Mark-H commented May 9, 2011

Copy link
Copy Markdown
Author

Did you select any items in your TV?

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

@neilp123

neilp123 commented May 9, 2011

Copy link
Copy Markdown

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
Copy Markdown

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

Mark-H commented May 11, 2011

Copy link
Copy Markdown
Author

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