We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 29674
    • 6 Posts
    I’ve been trying to post code examples (html, css, php) in documents, but they are being stripped out.

    I’ve disabled Cleanup on TinyMCE. What else is at work here?

    What is the proper way to post code examples with MODx?

    Thanks,
      • 7231
      • 4,205 Posts
      There is a snippet that allows this. I just can’t remember the name right now.
        [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't know what it is.
        Do you, Mr. Jones? - [bob dylan]
        • 11975
        • 2,542 Posts
        I guess this is this one authored by Garryn

        CommentTags
        --> http://modxcms.com/commentTags-1389.html

        :-)

        Edit: not this one smiley
        It is for modx code

        This one is what you’re after (CodePrettify)

        http://modxcms.com/CodePrettify-1650.html

        Or else this one

        http://modxcms.com/GeSHi-Syntax-Highlighter-628.html
          Made with MODx : [url=http://www.copadel.com]copadel, fruits et l
          • 7231
          • 4,205 Posts
          No I don’t think it is either one of those, I am not sure it is on the repository or not (I just did a search for all the obvious names and did not find it). I might have it bookmarked on my other computer, will check later.

          I know I am not nuts and I did see this around someplace...or have I lost it shocked
            [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't know what it is.
            Do you, Mr. Jones? - [bob dylan]
            • 3749
            • 24,544 Posts
            I have my own snippet for outputting MODx tags, but for php, html, and css, I usually just turn off the rich text editor and use the HTML entities for everything that would cause trouble (I don't have that much code to present on my site).
            
            Here's a snippet off the top of my head that will work, though. Each piece of code could go in its own chunk or directly in the snippet call (for short bits of code).
            
            Snippet: ShowCode
            Call: [[ShowCode? &codeChunk=`codeExample1`]]
            <br />or
            [[ShowCode? &rawCode=`<p>some raw code <b>here</b></p>`]]
            <br /><br />Snippet Code:<br /><br />[code<?php
            if (isset($rawCode)) {
            $output = htmlentities($rawCode, ENT_QUOTES);
            } else {
            $str = $modx->getChunk($codeChunk);
            $output =’<pre>’;
            $output .= htmlentities($str, ENT_QUOTES);
            $output .=’</pre>’;
            }
            return $output;
            ?> <br /><br />[Update 1/5/08: fixed a couple of typos and tested it. It works both ways and the chunk version will preserve your line breaks and your indenting.]<br /><br /><br />Hope this helps,<br /><br />Bob<br />
              Did I help you? Buy me a beer
              Get my Book: MODX:The Official Guide
              MODX info for everyone: http://bobsguides.com/modx.html
              My MODX Extras
              Bob's Guides is now hosted at A2 MODX Hosting
              • 22303 MODX Staff
              • 10,725 Posts
              Keep in mind that all MODx tags, <script> tags, and entities are stripped from all POST variables in the MODx front-end via /manager/includes/protect.inc.php. This kind of thing will be configurable in the future, but for now, you’ll need to modify the logic here to allow these types of posts in the front-end.

              As for the backend, you need to check any mod_security filtering going on as well; it may be stripping other HTML, CSS, JS code itself.
                • 7231
                • 4,205 Posts
                I guess the one I had seen was ShowSnippet (although I am not sure).

                http://modxcms.com/ShowSnippet-743.html

                I have not tested it but it seems to do what you describe.
                  [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]
                  • 3749
                  • 24,544 Posts
                  I have my own snippet for outputting MODx tags, but for php, html, and css, I usually just turn off the rich text editor and use the HTML entities for everything that would cause trouble (I don’t have that much code to present on my site).

                  Here’s a snippet off the top of my head that will work, though. Each piece of code could go in its own chunk or directly in the snippet call (for short bits of code).

                  Snippet: ShowCode
                  Call:
                  [[ShowCode? &codeChunk=`codeExample1`]]

                  or
                  [[ShowCode? &rawCode=`<p>some raw code <b>here</b></p>`]]
                  


                  Snippet Code:

                  <?php
                  if (isset($rawCode)) {
                      $output = htmlentities($rawCode, ENT_QUOTES);
                  } else {
                      $str = $modx->getChunk($codeChunk);
                      $output ='<pre>';
                      $output .= htmlentities($str, ENT_QUOTES);
                      $output .='</pre>';
                  }
                  return $output;
                  ?>


                  [Update 1/5/08: fixed a couple of typos and tested it. It works both ways and the chunk version will preserve your line breaks and your indenting. (Had to delete and re-post to get the post format right.)]


                  Hope this helps,

                  Bob

                    Did I help you? Buy me a beer
                    Get my Book: MODX:The Official Guide
                    MODX info for everyone: http://bobsguides.com/modx.html
                    My MODX Extras
                    Bob's Guides is now hosted at A2 MODX Hosting
                    • 29674
                    • 6 Posts
                    I didn’t realize my question would generate so much of a response. Thanks for all the ideas. While all are great, they’re not quite what I was looking for.

                    BobRay’s snippet is a good idea. However, for a site that would post lots of code, I feel it would be unmanageable with so many chunks.

                    I spent quite some time today and built a plugin that will serve my needs.

                    As soon as I clean it up a bit, I’ll post it.

                      • 3749
                      • 24,544 Posts
                      A plugin would be great. I look forward to seeing it.

                      Another way would be to put all the code in one file with a key for each section and then call a snippet with the key as a parameter. I think the plugin is a better idea, though.

                      Bob
                        Did I help you? Buy me a beer
                        Get my Book: MODX:The Official Guide
                        MODX info for everyone: http://bobsguides.com/modx.html
                        My MODX Extras
                        Bob's Guides is now hosted at A2 MODX Hosting