I am making an website for ourselves with some documentation about certain Extra’s etc.
Now i want to be able to put MODX snippets in there for easy copy-pasting, but i dont really know how i should escape the tags…
I put the code in a MIGX tv and display them in the chunk like so
The HTML tags get escaped but the MODX tags like [[snippet]] and [[+placeholder]] wont.
Escaping them manually with [\[ doesn’t work and just prints out the [\[formit? ... ]] making it not so easy to copy-paste.
I found a plugin called Escape MODx Tags but it doesn’t work ( I guess it’s for old modx/evo looking at the {{chunk}} tag):
<?php
// MODx Plugin: Escape MODx Tags
// Description: A simple system to escape MODx tags for display on a web page.
// Author: James Ehly
// Website: devtrench.com
//
// System Event: OnWebPagePrerender
// Usage: [\+tvName+], [\[cachedSnippetName]], [\!snippetName!\],{\{chunkName}}
$find = array('[\\','\]','{\\');
$replace = array('[',']','{');
$modx->documentOutput = str_replace($find,$replace,$modx->documentOutput);
Not sure, but I think the content of the placeholder and tags in it gets parsed before the outputfilter runs.
But it should be possible with a prepareSnippet, which runs on each row, before tags are parsed.
I use SyntaxHighlighter in combination with FixedPre. Syntaxhighligher gives you nice highlighting, a styled box for the code, and optional line numbers. The FixedPre plugin (which you can use by itself) will escape the MODX tags for you when you put them in FixedPre tags.
<fixedpre>[[Some MODX tag]]</fixedpre>
If you combine it with the SyntaxHighlighter plugin, the the FixedPre tags need to go in the inside: