We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 50497
    • 30 Posts
    First, let me say that Bob's ClassExtender Addon is absolutely brilliant. For those of you that haven't tinkered with it you have to give it a try.

    I do have a question about extending modResources for those of you who may have used the ClassExtender. I've gone through the tutorial and all is working well. I am curious if it's possibly to have the extended fields work more like TV's in the sense of when they are displayed. Is it possible to assign them to templates. Don't get me wrong it definitely extends the resource as though the new fields are inherently part of the resource much like the content or pagetitle field. That being said they are always there. I like the idea of being able to search the fields and them being within their own table, however I could see where there may be a need for different tables based on the resource content and hence different fields. So I'm trying to determine if it's possible to extend the resource, but only display the fields based possibly on the template that is chosen?

    In Bob's baked in example it covers extending the resource with dog breeds. However, what if you wanted two different tables with different fields let's say one for dogs and one for cats. At that point it would extend the resource showing all fields and I suppose the unwanted fields could just be left blank, however what if you had two different templates one named dogs and one named cats and based on that selection the appropriate extended fields would display.

    Anyone know if this is possible and how to go about achieving this behavior?
      • 3749
      • 24,544 Posts
      You might be able to hide the unwanted fields with Form Customization. I've never tried it, and I suspect that it won't work.

      I think the best approach would be to duplicate the ExtraUserFields plugin, disable it, and enable the duplicate. Then you could modify the plugin to have it select the fields to display based on the template or the content of a TV. If you have all the fields in one table, I think that would be enough, you'd be pulling fields you don't need, but I doubt if that would slow things down much. If you want a separate table (and I can see why you might, for search purposes), the plugin would have to also select the object to save and you'd have to duplicate and modify the SetResourcePlaceholders snippet as well. You might also have to do the same with the getExtResources snippet, I'm not sure.
        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