We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 51220
    • 17 Posts
    I have only middling development knowledge, so apologize if this question has an obvious answer. I need to create a way for the average user to view the source code of a document from the manager. Ideally, a button when they are editing a resource.

    For example, by default, you press "View" and it opens a new window with the page they've just created. What I would like is a similar action that goes straight to the source code of that page. (Even better would be if they could press a button to copy the source code to their clipboard, but I'll take what I can get.)

    I know they could press view and then CTRL+U or right click, but I am hoping to make it even easier for them.

    Am I overlooking how to do this?

    I'm using Revo 2.4.2.

    Thanks!

    This question has been answered by cwhissen. See the first response.

    [ed. note: cwhissen last edited this post 8 years, 5 months ago.]
    • They can see the cached output by right-clicking on the resource in the Tree, "Overview", and the Cache Output tab. This will show what's cached, which will include any uncached MODX tags.

      Of course, if a resource has just been created or edited, and the cache cleared, there won't be any cached version to view. So viewing the page, then viewing its source, is still the best way available.
        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
        • 51220
        • 17 Posts
        Quote from: sottwell at Oct 09, 2015, 11:15 AM
        They can see the cached output by right-clicking on the resource in the Tree, "Overview", and the Cache Output tab. This will show what's cached, which will include any uncached MODX tags.

        Of course, if a resource has just been created or edited, and the cache cleared, there won't be any cached version to view. So viewing the page, then viewing its source, is still the best way available.

        Thanks sottwell, it's good to know another way. Realistically though, that's a little more than I can ask from these users.
        • If that's the case with the users, then what is viewing the HTML source going to accomplish?
            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
            • 51220
            • 17 Posts
            They need to copy and paste the source code into another system. ModX is being used so they can easily create the necessary HTML, but they need the source code for the next step.

            Worst case they view page and then view source code, but it needs to be idiot proof if possible.
              • 3749
              • 24,544 Posts
              You can try wrapping your template in pre tags, though I think that may prevent any tags from being processed:

              <pre>
              
              // all template code
              
              </pre>
              


              A plugin attached to OnWebPagePrerender might work. The tags will have been processed by that point. The plugin code will look something like this:

              $modx->resource->_output = '<pre>' . $modx->resource->_output . '</pre>';
              return '';

                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
                • 51220
                • 17 Posts
                First, thank you for the answer BobRay. However, I don't think that will solve my problem. I still need them to be able to click View and see the rendered HTML. That's how they'll know to adjust the content to fit. The source view needs to be in addition to the regular preview. If I'm understanding correctly, wrapping with <pre> would give me the code only, right?

                I did try figuring out a way to prepend "view-source:" to the preview-url function, but I'm slightly out of my depth there. I couldn't get further than adding a source button that would open the preview. I might play with that a little more to see what I can do.

                Thanks all!

                P.S. BobRay, your forum answers and Bob's guide have been an immense help to me as I've worked on my first ModX project. Thank you!

                  • 51220
                  • 17 Posts
                  Actually, I think I was just sleepy last night and had missed the function I needed. I've figured it out! Let me test it a little more and then I'll post what I did for you guys to tear apart. smiley
                  • discuss.answer
                    • 51220
                    • 17 Posts
                    So, I changed things in two places - not sure that's was necessary, but it worked.

                    In both data.js and update.js I added the following function under the preview function:

                     ,viewsource: function() {
                            window.open("view-source:"+this.config.preview_url);
                            return false;
                        }


                    then I added a button after the view button:

                    btns.push({
                                text: _('source')
                                ,id: 'modx-abtn-viewsource'
                                ,handler: this.viewsource
                                ,scope: this
                            });


                    So far, I haven't been able to make it break.

                    Thanks for the answers everyone!