We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 27985
    • 54 Posts
    Hi,

    I’m wondering if anyone knows of a simple way to inject code comments into modX templates or chunks..
    I know I can just use html comments (<!-- comments -->), but I would like to avoid them being output to the final source.

    For instance [//this could be a comment]

    Does it exist?

    Thanks!

      MODx 2.0.6
      PHP 5.3.3
      MySQL 5.1.50
      • 28042 ☆ A M B ☆
      • 24,524 Posts
      Use a plugin to remove them during parsing. I seem to remember something about this before.

      Here’s a regular expression I found to find HTML contents; the plugin would use this to remove them.
      \<![ \r\n\t]*(--([^\-]|[\r\n]|-[^\-])*--[ \r\n\t]*)\>


      There are also some interesting functions in the user comments to this http://www.php.net/manual/en/function.strip-tags.php
        Studying MODX in the desert - http://sottwell.com
        Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
        Join the Slack Community - http://modx.org
        • 4041
        • 788 Posts
        You can also just wrap your comment in snippet tags something like this:

        [[this will be removed before page render]]

        or

        [!this will be removed before page render!]
          xforum
          http://frsbuilders.net (under construction) forum for evolution
          • 27985
          • 54 Posts
          I just thought of a solution, however convoluted:

          I could create a snippet so [[comment_snippet? &comment=`Put your comment here`]]

          Anyways, I feel like this would be nice to have in the core.
            MODx 2.0.6
            PHP 5.3.3
            MySQL 5.1.50
            • 17499 ☆ A M B ☆
            • 872 Posts
            They do not belong in the core, it’s not something that is required to build a website.

            The two solution posted above yours are legit.
            I prefer the one submitted by Sotwell, more cleaner.
              • 27985
              • 54 Posts
              Ok. Thanks for the reply everyone!

              I tried [[// Comment ]] which seems to work fine except:

              a. It’s invalid. I actually wonder if it is logging an error anywhere, which I wouldn’t like.
              b. It’s hard to differentiate from other modX syntax!

              This leaves me using standard HTML comment syntax or a subset of that, as they are easiest to read and valid. Perhaps as Susan suggested, just filter them out at runtime. Could do something like <!--- ---> to still allow <!-- --> to flow through.

              Thanks!


                MODx 2.0.6
                PHP 5.3.3
                MySQL 5.1.50