We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 10487 MODX Staff
    • 1,535 Posts
    Hi all,

    Most people know that if you want to prevent a MODx tag from being parsed in a page on a MODx site (for example, when writing a tutorial or documentation) then you can use the ole’ comment trick to prevent the parsing: [<!-- -->[mySnippet]<!-- -->]

    That solves one problem, but creates another ... how many people have been caught out when they do a copy and paste and wonder why things don’t quite work? Because, inadvertently, they have copied the commented tag over.

    So, here’s a simple little plugin that I’m developing as I redesign my personal site. The plugin attaches to the OnWebpagePrerender event and uses some simple regular expressions to remove the comments from the tags (as all MODx parsing is now completed at this point, they are displayed on the page in a niceCopy format wink ) The plugin itself may need a few tweaks here or there which is why I’m not yet posting this in the Repository.

    Not sure if something like this exists already, but thought I’d post it here anyway.
    <?php
    /**
    * Plugin: niceCopy v0.5
    * Author: Garry Nutting
    * Date: 22/01/07
    *
    * Event: OnWebpagePrerender
    */
    
    // delimiter
    $delim = '<!-- -->';
    
    // replacement arrays
    $replace = array(
    '/\['.$delim.'[(.*?)]'.$delim.'\]/ims',
    '/\['.$delim.'!(.*?)!'.$delim.'\]/ims',
    '/\{'.$delim.'{(.*?)}'.$delim.'\}/ims',
    '/\['.$delim.'\((.*?)\)'.$delim.'\]/ims',
    '/\['.$delim.'\+(.*?)\+'.$delim.'\]/ims',
    '/\['.$delim.'\*(.*?)\*'.$delim.'\]/ims',
    );
    
    $with = array(
    '[[\1]]',
    '[!\1!]',
    '{{\1}}',
    '[(\1)]',
    '[+\1+]',
    '[*\1*]'
    );
    
    // take copy of document output
    $output = $modx->documentOutput;
    
    // do replacement and send back to document output
    $output = preg_replace($replace,$with,$output);
    $modx->documentOutput = $output;
    ?>
    


    Have fun,
    Garry
      Garry Nutting
      Senior Developer
      MODX, LLC

      Email: [email protected]
      Twitter: @garryn
      Web: modx.com
      • 3026
      • 189 Posts
      thanks Garry
      it’s a great Work wink
        آموزش ساخت ماژول برای مد ایکس "قسمت اول"1
        http://modxcms.com/forums/index.php/topic,8990.0.html
        آمورش ساخت ماژول قسمت دوم2
        http://modxcms.com/forums/index.php/topic,9265.0.html
        کار با فرم الکترونیک مد ایکس
        http://modxcms.com/forums/index.php/topic,9305.0.html
        فارسی Skin graft ماژول پوسته ساز
        http://modxcms.com/forums/index.php/topic,9379.0.html
        • 27376
        • 576 Posts
        This is actually a plugin, not a snippet. But very cool indeed smiley
          • 22815
          • 1,097 Posts
          Good catch. Title corrected.
            No, I don&#39;t know what OpenGeek&#39;s saying half the time either.
            MODx Documentation: The Wiki | My Wiki contributions | Main MODx Documentation
            Forum: Where to post threads about add-ons | Forum Rules
            Like MODx? donate (and/or share your resources)
            Like me? See my Amazon wishlist
            MODx "Most Promising CMS" - so appropriate!
            • 15987
            • 786 Posts
            Great plugin Garry, I just added this to my site and it works great.