27 aug 2017
How to embed HTML-code in the text of page on MODx Evolution
By: Roman Kondrashov
For blogs related to programming, one often need to output code in the body of the post. For these purposes, several methods are best known:
- tag ;
- tag ;
- Google Code Prettifier;
For MODx Evolution, you'll have to output the code in the TinyMCE visual editor, then frame it with the code tag, and then add the pre tag NOT in the visual view. However, this method replaces the angle HTML brackets with mnemonic characters. It is not entirely convenient.
For WordPress there are plugins like crayon-syntax-highlighter, which cope with this task. But the situation is different with MODx Evolution, and none of the above methods works perfectly for HTML. Alternatives can be used if you do not use TinyMCE at all:
- <math> <![CDATA[Put codes here]]> </math>;
The last option is the most cute and works great with Prettifier. Download and connect these 2 files: http://seofocus.pro/vendor/prettify.css, http://seofocus.pro/vendor/prettify.js.
Add an onload event to the body tag:,and, in order for the code to be highlighted, we enclose the expression with CDATA with .
Some disadvantages: TinyMCE will destroy part of the code if you decide to save the post in this editor. And you will see the service code in the content, being logged in the admin panel, if you use the Quick Manager+ plugin. You say "duct tape"? Yes, it is. You know a better way or a plug-in? Welcome to comments.