We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 19328
    • 433 Posts
    When I create a new resource I can get the ID, template or parent etc. in a plugin like this:

    $resource->get('id');
    $resource->get('parent');
    $resource->get('template');
    


    But when I create a new resource and without saving change the template (and confirm the popup), I loose this information. The above code is not working anymore. Is there a way to get it after the template has changed? I can't get it from the URL, which changes to something like this:

    http://www.mywebsite.nl/manager/index.php?a=55&reload=53d7b3ad338e03.7743454350&class_key=modDocument&context_key=web

    Thanks for any help!
      • 28042 ☆ A M B ☆
      • 24,524 Posts
      That's because there is no resource until you save it.
        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
        • 19328
        • 433 Posts
        Yeah, sounds logical. But isn't there any way to get the info? Like POST data or something?

        To explain what I'm trying to do: I use the SEOPro addon but for certain resources I don't want it. Because this is not implemented yet I changed the plugin myself to not fire the plugin code on certain documents. I use this code for now (I know it's ugly):

        if (($resource->get('id') != 10) && ($resource->get('parent') != 10) && ($_GET['parent'] != 10) && ($resource->get('template') != 7) && ($resource->get('template') != 5) ) 
        { SEOPro code }
        


        So I don't want the plugin to act on Resource 10 and it's children, and also not on resources with template 5 or 7. This works when I first create a new document, because the parent is in the URL. But when I change the template on the new resource the URL changes and there is no way to get the information anymore (and the SEOPro widget is there again).
          • 28042 ☆ A M B ☆
          • 24,524 Posts
          Maybe you need to use a different event, to do it after the resource is saved?
            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
            • 19328
            • 433 Posts
            that would be better, however the SEOPro plugin uses the OnDocFormRender event so I have to intervene at that event. But it's not a really big problem, it would just be nicer if the SEOPro stuff wouldn't be visible at all for those specific resources. For now it works ok because as soon as the new resource is saved they do disappear. Thanks for your help!
              • 3749
              • 24,544 Posts
              It might be slightly more elegant to reverse your conditions and just "return '';"; if they're met rather than wrapping the whole plugin in curly braces.

              One issue on the SEOPro stuff is whether MODX calls OnDocFormRender again after the template changes (or calls a processor that invokes it). If not, the plugin code will always execute before the template is changed.
                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
                • 19328
                • 433 Posts
                Thanks Bob, good advice, I'll change that.

                It looks like onDocFormRender doesn't get called again after the template changes, because my code to exclude resources isn't executed at that time (but the SEOPro code is executed... strange). But I'm not sure I'm understanding it correct, I'll have a better look at it when I get the chance.