We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 36755
    • 41 Posts
    Hi all, is there a way to enable parsing of linebreaks as BR (html) from Content.

    I know it from other cms. No wysiwyg, pure html, but the parsing of linebreaks for the frontend.

    Thanks
      • 31946
      • 116 Posts
      I'm not sure if I understand you right. Your clients only have a textarea to manage the content?
      Then you can convert the Linebreaks with a snippet.
      Create a snippet "nl2br" with the code:
      <?php
      return nl2br($input);

      In your template, you can then pass the content as input and all linebreaks are converted to br:
      [[nl2br? &input=`[[*content]]`]]
        • 36755
        • 41 Posts
        @Wanze: AWESOME!

        Thanks a thousand smiley

        Exactly what I needed.
          • 36755
          • 41 Posts
          @Wanze: Now I tried to implement this in MODX EVO, but it does not work.

          As soon as there is a =" in the content, the parser seems to break.

          E.g. content:
          This is <span style="font-size:15px;">a test</span>
          becomes
          This is <span styl
          and breaks the output of content!

          Any ideas?

          PS: Call of the snippet in modx evo with:
          [!nl2br? &input=`[*content*]`!]
            • 36755
            • 41 Posts
            Btw, changing the snippet to only return the passed content leads to the same mistake!

            <?php
            return $input;
            ?>
              • 36755
              • 41 Posts
              [SOLVED] it by changing the snippet to:

              <?php
              	$content = $modx->getTemplateVarOutput('content', $pageID);
              	return nl2br($content['content']);
              ?>


              naming it getContent_nl2br and calling it without arguments in the template:
              [!getContent_nl2br!] [ed. note: kajus99 last edited this post 14 years, 8 months ago.]
                • 31946
                • 116 Posts
                hi kajus99,
                Unfortenately I don't know much about evo.
                For revolution, I just realized that there is existing already an "nl2br" output modifier for your elements, so you don't even need the extra snippet.
                See:
                http://rtfm.modx.com/display/revolution20/Input+and+Output+Filters+%28Output+Modifiers%29#InputandOutputFilters%28OutputModifiers%29-Stringoutputmodifiers