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

    I've written a small snippet that creates an absolute path to a thumbnail of a larger image. I've tested it on a page containing the larger image and it outputs the path as expected.

    When I try to use that snippet on a getResources tpl it doesn't work. I tried a workaround by putting the snippet call in a TV and retrieve that TV through getResources. That too fails, what Am I doing wrong?

    Here's the snippet:

    //Get TV Value
    $tvid = 89;
    $tvval = $modx->resource->getTVValue($tvid); 
    
    //Get poster path
    $poster_path = pathinfo($tvval);
    
    //Output thumb path
    echo $poster_path['dirname'] . "/thumbs/" . $poster_path['basename'];


    Here's the getResources tpl

    <a href="[[~[[+id]]]]" class="thumb">                            
      <span class="duration">[[+tv.ClipDuration]]</span>
      <span class="caption">[[+pagetitle:limit=`30`]]</span>
      <img src="[[MessageThumbPath]]" width="203" height="103" alt="[[+pagetitle]]" />
    </a>
    <!--/ Item -->


    --EDITS

    I even tried using @EVAL on a TV, but all I'm getting is: /thumbs/ which tells me it's not outputting the dirnames and file names

    here's my EVAL code:

    @EVAL $tvid = 89; $tvval = $modx->resource->getTVValue($tvid); $poster_path = pathinfo($tvval); echo $poster_path['dirname'] . "/thumbs/" . $poster_path['basename'];


    Any thoughts? [ed. note: treigh last edited this post 14 years, 4 months ago.]
      A MODx Fanatic
      • 30912
      • 463 Posts
      only thing i can see at first glance is

      <img src="[[MessageThumbPath]]" 
      is missing a + and should be
      <img src="[[+MessageThumbPath]]" 


      as for the code - i cant help sorry - im useless with snippets
        • 19369
        • 1,098 Posts
        @Tyreal2012, that's a snippet. So the problem is not there.
          • 30585
          • 833 Posts
          @microcipcip, any idea why this is not working?

            A MODx Fanatic
            • 19369
            • 1,098 Posts
            I don't know, I am not a coder. Have you tried it uncached?
              • 3749
              • 24,544 Posts
              Calling it uncached might work:

              [[!MessageThumbPath]]


              Also, use return rather than echo in the snippet. You shouldn't need an @EVAL statement.



              ------------------------------------------------------------------------------------------
              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
                • 30585
                • 833 Posts
                @BobRay I just tested the snippet call uncached and used return instead of echo, but no - This thing isn't giving. I also cleared the cache for the purpose. All I'm getting in the source code is the string part "/thumbs/" which means that the snippet might be working, but for some reason it's ignoring the tvval.

                The reason I'm trying this method is to avoid overusing the wonderful phpthumbof. I find that zoom-cropping more than 20 poster images with phpthombof to create thumbnails of ~15kb each on the same page even with getResources cached makes the loading painfully long. Also, for SEO purposes, I want certain thumbnails indexed. So I''ve decided minimizing the use of output filters like phpthumbof.

                This is taking too long though, is there another way to achieve the same thing? Since the real thumbnails are kept in a directory 1 level lower than the larger images, I thought there should be an easier way to retrieve them. I have no drama getting the larger images.
                  A MODx Fanatic
                  • 19369
                  • 1,098 Posts
                  Is it possible that the snippet is looking for the ID of the page you're in, and not the ID of the page in the getResources snippet?
                    • 3749
                    • 24,544 Posts
                    Good catch microcipcip. wink


                    $modx->resource will always point to the current resource (the one with the getResources tag). You'll need to add a property to your snippet to pass it the ID of the page GR is getting:

                     [[!MessageThumbPath? &pageId=`[[+id]]`]]



                    Then get the ID in your snippet with:

                    $id = $scriptproperties['pageId'];


                    Your snippet will have to be uncached and it could still fail due to the parsing order, but it's worth a try.


                    ------------------------------------------------------------------------------------------
                    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
                      • 30585
                      • 833 Posts
                      @BobRay and @microcipcip , thanks for seeing that. It makes a lot of sense now.

                      I did declare the $id in the snippet, just before $tvval, but it didn't work. I should also point out that I'm using getresources via getPage@Pagination. Is that a problem
                        A MODx Fanatic