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
    Is there any way to assign a media source to resources? For example, having a structure of image folders such as images/dogs and images/cats is there a way to have a media resource for each, then have the dogs resources use the dogs media resource and the cats resources use the cats resource?
      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
      • 40385
      • 75 Posts
      As far as I know not directly, but you can try bypassing this by assigning the media source to a specific TV...meaning you have create two TVs: one for dog images and one for cat images

      http://rtfm.modx.com/display/revolution20/Assigning+Media+Sources+to+TVs
        • 28042 ☆ A M B ☆
        • 24,524 Posts
        Right. I was thinking of the image insertion feature of the rich text editor.

        I've often wished that resources had categories as well as elements, and that TVs and Media Sources and other elements could be assigned to resources by category.
          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
          • 4172
          • 5,888 Posts
          you can place a snippet into the mediasource-pathes which gets the parent and replaces the path dynamically.

          assets/[[getParentFolder]]
            -------------------------------

            you can buy me a beer, if you like MIGX

            http://webcmsolutions.de/migx.html

            Thanks!
            • 28042 ☆ A M B ☆
            • 24,524 Posts
            That is interesting. Opens up a whole new set of possibilities.

            I'll have to give that a try and see how it would work. I'm still a Revo neophyte, so I'll have to first figure out how one fetches the current resource's parent in a snippet. I presume that [ [*parent] ] wouldn't work there?
              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
              • 40385
              • 75 Posts
              Great! I didn't know that...thanks
                • 3749
                • 24,544 Posts
                Susan, $modx->resource->get('fieldName') will get you any field for the current resource, so $modx->resource->get('parent') will get you the parent's ID.

                If you wanted the parent's pagetitle, you'd do this:

                <?php
                $parentId = $modx->resource->get('parent');
                $parentObj = $modx->getObject('modResource', $parentId);
                $parentName = $parentObj->get('pagetitle');
                



                ------------------------------------------------------------------------------------------
                PLEASE, PLEASE specify the version of MODX you are using.
                MODX info for everyone: http://bobsguides.com/modx.html
                  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
                  Ok... this doesn't solve the question of how to assign a Media Source to the resources.
                    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
                    Sorry, should have read the OP more carefully. I haven't really had occasion to use Media Sources, but my impression is that they don't work with Resource (but I could well be wrong). I know you can assign one to a TV and probably to a static chunk, if that would help.


                    ------------------------------------------------------------------------------------------
                    PLEASE, PLEASE specify the version of MODX you are using.
                    MODX info for everyone: http://bobsguides.com/modx.html
                      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
                      That's OK, learning that we can use tags in the media source path and URL is great! Also your tips on fetching information.

                      I think that since the value being returned is to correspond to a directory name, perhaps just using the parent's ID would be a better idea. Resource pagetitles often have spaces and other characters that would choke a filesystem. If snippets can be used, can default resource values such as [ [*parent] ] be used as well? One way to find out, I suppose, is to give it a try in an image TV.
                        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