We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 38850
    • 110 Posts
    I came across this Javascript tool which does HTML inspection to look for issues.
    The tool itself is quite advanced as far as adding custom filters and options, but the defaults are also fine.

    https://github.com/philipwalton/html-inspector

    Using their CDN and code, I wrote the smallest little plugin to put this into my project globally.

    Create a plugin called "HTML Inspector" or whatever you like. Insert this code:

    <?php
    // reference the output
    $output = &$modx->resource->_output;
    $output = str_replace("</body>",
    '<script src="http://cdnjs.cloudflare.com/ajax/libs/html-inspector/0.8.1/html-inspector.js"></script>
    <script> HTMLInspector.inspect() </script>
    </body>',
    $output);
    


    Attach the plugin to the system event "OnWebPagePrerender" which would be at the bottom of the list.

    Only enable this plugin during development, as it will slow down page load a little bit.

    To use it, just open your web browser tools and open the console. The tool outputs any issues to the console that it finds in your HTML source.

    The plugin itself simply looks for the closing "</body>" tag and inserts the two scripts above that.

    If you wanted to limit tests to only certain pages or contexts or parent tree, etc, you'd have to edit it further for your needs.

    ----------------

    This is a very generic way to insert scripts globally into code. I initially used this script by editing my templates, but then I also had to edit my footer chunks, and deal with user auth logic and snippets. I ended up having to put code in 4 places to use this. This would be a pain to have to come back and remove whenever I don't need the tool.

    By using a plugin, it loads on every page, and I can just disable the plugin when not needed.

    This use of a plugin, on page prerender, is a good generic way to load scripts globally with a single enable/disable function. It helps me avoid putting "temporary" scripts into my templates/chunks/snippets that I have to remember to remove again later.

    There may be an existing plugin that does this sort of thing more elegantly, but based on how easy this was, I just did it myself without even searching for something better.
    • Nice! I will check it out!
        Benjamin Davis: American web designer living in Munich, Germany and a MODX Ambassador. I am also co-founder of SEDA.digital, a MODX Agency.
        • 3749
        • 24,544 Posts
        Nice! ")

        Are you planning to release it as an extra?
          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
        • Here is it as a snippet that you can put at the top of a template - don't forget that adding a - ([[-snipName]]) is the "official" way to disable a snippet.
          <?php
          $modx->regClientScript('http://cdnjs.cloudflare.com/ajax/libs/html-inspector/0.8.1/html-inspector.js');
          $js = '<script> HTMLInspector.inspect() </script>';
          $modx->regClientScript($js);

            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
            • 38850
            • 110 Posts
            Quote from: sottwell at Jan 09, 2015, 05:12 AM
            Here is it as a snippet that you can put at the top of a template - don't forget that adding a - ([[-snipName]]) is the "official" way to disable a snippet.

            Even if I did it this way, I'd still have to go disable the snippet call from multiple locations.

            My technique was so I could insert a script universally no matter which template or template chunks/snippets I used.

            Bob - It's not worth making an extra at this point, but as a general concept "universal script insert tool", if such doesn't exist already.

            Maybe with some more features and properties it would be worth it, otherwise I just found this method handy.
              • 3749
              • 24,544 Posts
              I think an html inspector plugin would be an OK extra by itself, even without the options, since you can easily turn it off and on and that would probably be easier than adjusting the options.

              Let me know if you're not going to to it and I'll add it to my very long list of extras I plan to release someday. wink
                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
                • 38850
                • 110 Posts
                Quote from: BobRay at Jan 12, 2015, 04:10 AM
                I think an html inspector plugin would be an OK extra by itself, even without the options, since you can easily turn it off and on and that would probably be easier than adjusting the options.

                Let me know if you're not going to to it and I'll add it to my very long list of extras I plan to release someday. wink

                Thanks for the encouragement. It would be my first extra then. I don't know what is involved in preparing an extra for public release or how to properly test it against any kind of environment and various MODX versions etc.

                Is there a standard protocol somewhere that explains how to release an extra into the market and the best way to monitor it over time? And how to actually package the snippet into an extra?

                I would just want to do everything "right" is all I'm saying. Any guidance is appreciated, I would love to contribute.
                  • 3749
                  • 24,544 Posts
                  I don't know of any official (or even semi-official) protocols. I create my extras with MyComponent, which makes them much easier to maintain and update, though it takes some work to get used to it. I used to test them on every new release, but there as so many of them now that it's not practical. I rely on users to report problems.

                  If you place the files and directories under assets/mycomponents/packagename as described here: http://bobsguides.com/mycomponent-tutorial.html, all you'll have to do is create a new project in the form, run BootStrap, edit the single config file, and run Import Objects and Export Objects, fill in the readme and tutorial files, run Build, and you'll have a package. Once the files are written, I can do a new package, ready to release, in about 20 minutes at the most. Then, you just go to modx.com/extras, fill in the info, and upload the transport file.

                  If all you have is the plugin, and you don't plan any other packages, you could also use PackMan, which is much simpler.

                  It's nice to put your package up on GitHub, where people can file bugs and feature requests and offer pull requests for them, but it's not required.
                    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