I’m a purist, so I hate rich-text editors. They clutter up the code in the database in ways that I do not desire.
Of course, for the non-HTML savvy this is a good thing. As they make it much more accessible. For a coder like me, a little less.
Hence this simple snippet to replace the [*#content*] in the template. It will automatically format the lines according to how you want them formatted. In this case between "line" method and "paragraph". The first treats each line literal by showing (text)
, the second treats each line as a paragraph by showing <p>(text)</p>.
How to do it?
Create a snippet:
showContent <?php
// Method, either 'paragraph' or 'line'
$method = (!empty($method) ) ? $method : 'line';
$content = $modx->documentObject['content'];
//Remove windows linebreaks.
$content = str_replace("\r", '', $content);
//Split the content into natural lines.
$lines = split("\n", $content);
$result = "";
foreach ($lines as $line) {
//Trim whitespaces (space, return, tab, etc.) From the front and the back.
$cur = trim($line);
if ($method == 'line') {
$result .= $cur.'<br />'."\n";
} else {
if (!empty($cur) ) {
$result .= '<p>'.$cur.'</p>'."\n";
}
}
}
return $result;
?>
Replace the
[*#content*] in your template with
[!showContent? &method=`paragraph` !] and Voila!
As with most of my snippets, it’s just clean and simple to either use or learn from.
Enjoy!