We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 21560
    • 145 Posts
    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!
      [font=Times]Comics, stories, music, graphics, games and more! http://Nimja.com
      • 7231
      • 4,205 Posts
      Nice, thanks.
        [font=Verdana]Shane Sponagle | [wiki] Snippet Call Anatomy | MODx Developer Blog | [nettuts] Working With a Content Management Framework: MODx

        Something is happening here, but you don&#39;t know what it is.
        Do you, Mr. Jones? - [bob dylan]