Output Modifier & SimpleSearch Lexicon

I’m trying to use an output modifier in the SS lexicon simplesearch.results_found to further customize the current message and display a slightly different version based on where the user searches.

For example, when the user searches a specific folder (e.g. parent=2, parent=3, or parent=4) they will see one message, and when they search the entire site (parent=0) they will see a slightly modified one.

Here’s the current message which works great:

[[+count]] article[[!pluralFilter? &count=[[+total]]]] with the term “[[+text]]” in [[!GetTitle]].

I just need to tweak it a tiny bit since there is nothing for [[!GetTitle]] to return for parent=0 so I want to hardcode an adjustment.

This is just a guess but since I’m using [[!getUrlParam]] as part of the SS form I was thinking maybe the output modifier could be written to check which parent was searched (parent=0, parent=2 etc.) and use that to display the correct message.

For example, (I know this does not work but you get the idea): [[!getUrlParam:is=parent=0:then=my custom message:else=[[!GetTitle]] ]]

Possible? If not then any other method will suffice.

Assuming that [[!GetTitle]] is a custom snippet you wrote, isn’t it just simpler to adjust that snippet than to use an output modifier?

If you really want to use an output modifier, this is the correct syntax:

[[!getUrlParam:is=`0`:then=`my custom message`:else=`[[!GetTitle]]`? &name=`parent`]]

It is a custom snippet but I didn’t write it. If I remember correctly it was most likely @bobray.

$fields = array('name' => 'parent');
$docId = (int) $modx->runSnippet('getUrlParam', $fields);
$query = $modx->newQuery('modResource', $docId);
return $modx->getValue($query->prepare());

So you already run the snippet getUrlParam in this code.

$docId = (int) $modx->runSnippet('getUrlParam', $fields);

Check if $docId is equal to 0 and return your custom message:

if ($docId == 0){
    return 'my custom message';

Absolutely perfect.

It didn’t occur to me to modify the snippet. Much cleaner.

Thank you.