We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 28042 ☆ A M B ☆
    • 24,524 Posts
    The site_resources table has a 'properties' field. In some cases, such as in the case of WebLinks, I see a JSON string there. How is this accessed? Does it have to be a JSON string? I can't find any documentation on it at all.
      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
      • 22303 MODX Staff
      • 10,725 Posts
      See the getProperties() and getProperty() methods in modResource. This does need to be added to the documentation, and has been available since 2.2.1 IIRC.

      There properties are namespaced and are meant to store custom data for use when viewing. This is a quick and easy way to add custom data to Resources, without having to create a CRC. It could also be used to summarize data from custom tables for use in a Resource view. This latter approach has the advantage of providing quick access to read-only properties directly from the Resource while still providing robust search/sort/filter/admin capabilities on the custom data tables.
        • 28042 ☆ A M B ☆
        • 24,524 Posts
        That doesn't tell me how to use the field. For example, supposing I want to specify a Media Source to use with a Static Resource (yes, I'm still flogging that horse, it keeps coming back to life). Would I need to use a plugin, or can I use a Form Customization to add a field to the editing form? What namespace?
          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
          • 3749
          • 24,544 Posts
          I think you could add the field with a Custom Resource Class that extends modStaticResource, but that's a lot of work just to get one more field. Any chance it can be done with a TV? That would be a whole lot easier.

            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
            • 28042 ☆ A M B ☆
            • 24,524 Posts
            Yes, I'm using a TV now. Just trying to figure out ways to minimize things.
              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
              • 22303 MODX Staff
              • 10,725 Posts
              The whole point of properties is to add read-only "data" to a Resource without requiring an externally joined relation, like a Template Variable is.
                • 28042 ☆ A M B ☆
                • 24,524 Posts
                Exactly what I want to do. When saving a static resource, I want to specify what Media Source it's supposed to be using. Then on page load I can fetch the path of that media source and prepend it to the path (the content) of the static resource.

                I'm also having a serious problem trying to figure out what system event I can use in a plugin to modify the static resource's content to prepend the media source path, irrespective of where I get that path from. As far as I can tell, the only event I can use for this is the OnParseDocument, which is triggered multiple times, making modifying the 'content' extremely difficult.
                  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