Drop-down list snippet for manager TV broken in 3.0.0

A snippet to create a drop-down list of categories so that publication resources can be listed in multiple categories, pulling the categories from the pagetitles of a set of otherwise blank child resources, was working okay but then broke when upgrading to 3.0.0. The way it breaks is that instead of showing the dropdown list in the relevant publication resource TV, it merely prints the code I entered in the template variable input list options field:

@EVAL return $modx->runSnippet(‘listMyResources’,array(‘parent’ => 26));

Can someone tell me what needs rewriting to unbreak it?

The TV has input type: Listbox(multi-select), and in the Dropdown list options field I have:

@EVAL return $modx->runSnippet(‘listMyResources’,array(‘parent’ => 26));

The listMyResources snippet then looks like this:

$parent = $modx->getOption('parent',$scriptProperties,26);
$parentObj = $modx->getObject('modResource',$parent);
if (!($parentObj instanceof modResource)) { return ''; }
$resArray = $parentObj->getMany('Children');
$resources = array();
foreach($resArray as $res) {
  if ($res instanceof modResource) {
    $resources[] = $res->get('pagetitle') ;
  }
}
$out = implode("||",$resources);
return $out;

Does that just need tweaking somewhere to make it work in 3.0.0 or does it need a total rewrite?

I see on the documentation page below it says that the drop-down menu TV input type has been deprecated. Does that mean that it is wrong to even try to do this? If so, what is the right way of enabling a client to categorise a publication resource under one or more categories?

https://rtfm.modx.com/current/en/building-sites/elements/template-variables/input-types#TemplateVariableInputTypes-AdvancedUsage

I believe the problem is, that the @EVAL binding has been removed in MODX 3.

https://docs.modx.com/3.x/en/building-sites/elements/template-variables/bindings/eval-binding

I think there exists now a @SNIPPET binding that you can use instead.
Or if this doesn’t work, use a @CHUNK binding and put your snippet call into a chunk.

2 Likes

Thank you very much, Harry. While you were typing that, I somehow found the page below going back to 2012

according to which it ought to be enough just to type something like this in the dropdown list options field on the TV input options page:


@SELECT `pagetitle`, `pagetitle` FROM modx_site_content WHERE parent=26 AND published=1 AND deleted=0

Tried it now and it seems to work a treat, meaning that the old snippet was the wrong way to do things right from the start. No need for a snippet at all.

1 Like

Try the superboxselect extra.

2 Likes

Superboxselect looks more powerful, but since I can now do all I need to do with one line of code on the template variable settings page, I am happy to stick with that for now.

In case someone wants to see the categories in use, they can be seen listed in the publications boxes in the News and Publications section further down this page:

This topic was automatically closed 2 days after discussion ended and a solution was marked. New replies are no longer allowed. You can open a new topic by clicking the link icon below the original post or solution and selecting “+ New Topic”.