•Try•
Catch

Escaping the MODX Parser

Tricking the Parser with the Parser

So you started using MODX, fell in love, and started blogging about it? You went to display some MODX code on your blog post and instead of displaying correctly it was parsed. Your output resulted in either nothing or something unexpected. Uh oh.

There are a few work arounds to this problem. Garry Nutting has a plugin to prevent MODX tags from parsing.

Another work around is to give in and let the MODX parser do it's thing. To satisfy the parser, we wrap the tag we would like to escape. Create a new Chunk with the following code:

    [[+input:notempty=`[[[[+input]]]]`]]

You can then echo MODX tags without parsing them. For example:

<p>
   [[$esc? &input=`$my-chunk`]]
</p>

Will output:

[[$my-chunk]]

We can even get real crazy with nesting MODX tags. For example:

[[$esc? &input=`$my-chunk? &amp;p=&#96;[[$esc? &input=`$other-chunk`]]&#96;`]]    

Will output:

[[$my-chunk? &p=`[[$other-chunk]]`]]

That's enough entities for the day. We should stop. You may also want to check out the tag Output Filter.

Comments (0)


Add a Comment





Allowed tags: <b><i><br>Comment:


** Time spent on this website is non-refundable **

modmore