Stop Custom Snippet from Parsing Placeholders

What’s the best way to stop MODX from parsing any [[+placeholders]] that get passed in thru TPLs?

I saw a post that mentions using @session_write_close(); as part of a solution for this. But I’m not sure that’s what I need.

Can tell us exactly why you want to do this? We need more information before we can answer your question.

I’m outputting content that will be subsequently used as MODX content. For example: I’m looping through a list of pages that have placeholders in their longtitle and content such as [[++city]]. The result of this loop needs to retain the MODX placeholders intact because it will then be copied/pasted into other resources.

I was just wondering if there is something simple that you need to do during PHP output that would stop it from parsing the placeholders.

I’m looking into $modx->getParser() and $modx->getChunk(). I see different tactics for processing different placeholders. But haven’t seen anything for not processing any of them.

If you load a modChunk object from the database and just read the value of the field “snippet” ($mychunk->get("snippet") or $mychunk->getContent()), then no parsing will take place.

Placeholders that are not yet available in a $modx->getChunk call will be returned as-is and rendered later. Depending on where the code runs and where [[++city]] comes from, that may or may not be available.

If you want to treat a value (such as a page’s longtitle that holds that [[++city]] placeholder) then you might want to encode [ and ] to ] and [ respectively. That’ll leave them alone.

Then perhaps in a later stage you need to decide them again to allow MODX to parse it.

Alternative approach: load whatever placeholders you’re expecting before the loop so a single pass is sufficient.

A few more thoughts. When you edit them in the Manager, the tags are not parsed, so if people can cut and paste them from there, you’re done.

Another option is to put them inside <pre> tags in the chunk and use the SyntaxHighlighter extra to display them. That should keep them from being parsed, and they can be copied as long as the cut and paste doesn’t include the pre tags.

You could also change the enclosing brackets like this: {{+tag}}. Then convert them to square brackets when you need to use them.

Another way to go would be to use an entity for the first [ of the tag: &#91; – that way they won’t be parsed, but should still work after a cut and paste operation.