We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 13226
    • 953 Posts
    Hi all,

    I am at my wits end. I am trying to re-create the file path of an image using the alias of each folder via Ditto.

    The path = assets/images/folder alias 1/folder alias 2/folder alias 3/IMAGE FILE IS HERE

    As I couldn’t find placeholders within Ditto for what I need, I reverted to the GetParent Snippet as it is extremely versatile and suits exactly that what I need.

    My Ditto Call:
    [!Ditto? &parents=`10` &display=`1` &depth=`3` &hideFolders=`1` &tpl=`RandomImage` &showPublishedOnly=`1` &randomize=`1`!]
    


    My Ditto Template Chunk (RandomImage):
    <img src="assets/images/[[GetParent? &field=`alias` &level=`2`]]/[[GetParent? &field=`alias` &level=`1`]]/[[GetParent? &field=`alias` &level=`0`]]/[+alias+].jpg" alt="[+longtitle+]" />
    


    The Result Is:
    assets/images////MYALIASNAME.jpg
    


    As can be seen from the above, Ditto doesn’t process the GetParent snippet parameters. (I use the GetParent snippet outside of Ditto and it works perfectly.)

    I have tried with various cached and uncached scenarios as well as a combination of caching and uncaching pages that display the call.

    I am not a PHP’r and so am somewhat restricted when it comes to interpreting php.

    If anyone can help that would be great.

    Cheers for reading and thanks for any help smiley
      • 18373 ☆ A M B ☆
      • 3,141 Posts
      Afraid I can’t help you solve that problem, but can I just ask why your image is hidden so deep?

      If I wanted to show a random image based on a certain resource (?) I would make a folder in assets/images/random, and put in the files there with the ID of the resource as the name.
        Mark Hamstra • Developer spending his days working on Premium Extras and a MODX Site Dashboard with the ability to remotely upgrade MODX and extras to make the MODX world a little better.

        Tweet me @mark_hamstra, check my infrequent blog at markhamstra.com, my slightly more frequent ramblings at MODX.today or see code at Github.
        • 13226
        • 953 Posts
        The image is in its own folder with the rest of the files that belong to that folder/page group

        Randomising doesn’t automatically mean getting any old image or document - this site is set-up for specific pages to have specific images. A form of "promote to front".

        The site where this function is to be used currently has around 2800 pages, with further static pages that use the MODx API to include functionality.

        Ease of use (assets/images/random/) is easy to set-up, but a website with a hierarchical structure isn’t sad

        I have come up with a dirty solution - by using [~[+id+]~] within the path:

        <img src="assets/images/[~[+id+]~]/[+alias+].jpg" alt="[+longtitle+]" />
        


        The problem with this is that it only works when FURL’s are activated.

        Maybe someone can find a different more friendly way to get around this problem.