[SOLVED] Simple Search issues snippet calls in search results


Snippet calls are also output with the search results output.

Step to reproduce

Add a PHP snippet to any page and search for it on Simple-Search.

Observed behavior

Image 1 = Image 1
Image 2 = Image 2

Expected behavior

In my view, Simple Search should either process the snippets OR not output them.


modx-version 2.8.1

I can’t reproduce this.

Where do you see the tags? In the extract?
Can you give a specific example (page content, search result template)?

See linked images above. Yes, you can see it in the search results. A part of the snippet is displayed in the search results.

Content on the testsite “dev123” (You can also use another snippet.):

Output on the dev123 Site > longtitle from the page, level top 2 > it works fine

Snippet-Call on the Search-Result-Site:

Output on simple search:

1. [dev123]

&field=longtitle &top=2`

Another test

Content on the testsite:

   &then=`Jup, its the site Kontakt`
   &else=`Nope, it's not`

Output on the site:


I can see that it doesn’t work on your website. Unfortunately when I test it, it works as expected and the tags are deleted.

The tags are deleted here in the code

and then here again

No idea, why it doesn’t work on your site.

Yes, this is also included in the code for simplesearch. Exactly the same as yours.

I don’t know why it doesn’t work for me. :face_with_raised_eyebrow:

In the meantime, I have also tested it on another site, the same problem, but other server requirements, other MODX version.

So what I found out: The double [[ characters generate the problem.

That doesn’t work:

   &then=`Jup, its the site Kontakt`
   &else=`Nope, it's not`

That works fine:

   &then=`Jup, its the site Kontakt`
   &else=`Nope, it's not`



$text = preg_replace('/(\[\[\+.*?\]\])/i', '', $text);


$text = preg_replace("/\[[^][]*+(?:(?R)[^][]*)*+]/i", '', $text);

Glad you found a solution.

But I mistakenly linked the wrong line in the code.
It’s actually the following line ($this->modx->stripTags($text);) that removes the MODX tags (including nested tags).

As this is a function of the MODX core code, I’m suprised that it doesn’t work.

If you create a snippet with this code:

$text = "text before[[!If? &subject=`[[#2.pagetitle]]` &operator=`EQ` &operand=`Kontakt` &then=`Jup, its the site Kontakt` &else=`Nope, it's not`]]text after";
return $modx->stripTags($text);

Does it remove the MODX tags correctly?