We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 13808
    • 61 Posts
    Burnt 2 hours trying to find a solution to this now - figure it’s time to check my thinking. Thanks to anyone who casts their eye over this. I’m using Evolution 1.0.0 and I’m having issues accessing variables I believe I’m passing correctly from a chunk to a snippet call.

    I have a chunk which is being called by Ditto with the contents:
    [[GraphHLStarter? &toLinkTo=`[+GraphicLink+]`]]<img src="[+GraphicHighlight+]" />[[GraphHLFinisher? &toLinkTo=`[+GraphicLink+]`]]


    I’ve whittled my snippets (named GraphHLStarter and GraphHLFinisher) all the way down to:
    <?php
    return 'Test' . $toLinkTo;
    ?>


    When I run the page, all that gets returned is ’Test’ and no value in place of $toLinkTo. I noticed that there’s some mention around the place of using [!...!] calls (non-cachable). When I do that though, the snippet doesn’t run I just end up with the call listed in my code. I do know that [+GraphicLink+] does have content which isn’t getting through because when I break the call by using the exclamation marks, I see can see the full call in my output (e.g. [!GraphHLStarter? &toLinkTo=`Get-Connected/life_groups`!] )

    I’m using no editor to edit my chunk, so it’s not that it’s ending up with extra garb around it. The snippet definitely gets called - I just don’t seem to be able to access my variable to work with it.

    Any help/thoughts would be very much appreciated!
      • 3749
      • 24,544 Posts
      Wrong tag wink

      If the information you want is in a chunk, you need a chunk tag {{ChunkName}}.

      [[GraphHLStarter? &toLinkTo=`{{GraphicLink}}`]]<img src="{{GraphicHighlight}}" />[[GraphHLFinisher? &toLinkTo=`{{GraphicLink}}`]]


      Before you rush off to change it, however, consider putting the info in Template Variables rather than chunks, especially if it might be different for different pages. That way you can edit it on the page itself rather than having to navigate to the chunk.

      Also, check out the @CHUNK binding for Template Variables to see if that might work for you.

      If you use a Template Variable, you’ll want a tag like this in the snippet parameters:

      &toLinkTo=`[*GraphicLink*]`
        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
        • 13808
        • 61 Posts
        Thanks for the quick response!

        The information I want is actually in a Ditto place holder. Ditto calls the Chunk which calls the Snippet. Unfortunately it seems Ditto can’t call a snippet, so this seems to be the way to any dynamic content based on a Ditto result. Does this make [+...+] the right tag? I found that when I changed it to [*...*] the variable was empty even before it was passed (being able to see the call with the [!...!] which isn’t working showed me that there was no data where there was data before).

        EDIT:
        I just looked into binding and from what I can tell, it won’t solve my issue.

        Now wondering if I could use a resource ID based workaround to this - rather than pass the placeholder through as a variable, see if the document ID is being passed and grab the TV directly using that. Fingers crossed Ditto doesn’t add a layer of abstraction here...
          • 27708 MODX Staff
          • 2,502 Posts
          I think what you might be running into is issues with order of execution. Are you trying to get data from the ditto call and resend it to the ditto output? This might not work. You may have to write your snippet to grab the data from the document directly instead of via a ditto placeholder or even a snippet.

            Author of zero books. Formerly of many strange things. Pairs well with meats. Conversations are magical experiences. He's dangerous around code but a markup magician. Blog ✦ Twitter ✦ LinkedIn ✦ GitHub
            • 13808
            • 61 Posts
            smashingred: exactly what I’m trying to do. Ditto result displayed via a Chunk which is calling a Snippet to output back into the Chunk (convoluted I know - if only Ditto could do something in terms of running PHP on a result).

            Will try stepping back the process and see what I can get working. I wouldn’t have thought that wanting to run PHP on a Ditto result would be all that uncommon - really wondering if I’m just missing something...
              • 20413
              • 2,877 Posts
              http://ditto.modxcms.com/files/snippet-ditto-php.html#save
              Example
              [[Ditto?parents=`1,2,3` &id=`someID` &save=`3` &paginate=`1`]]
              [!MySnippet? &param=`[+someID_total+]`!]

              Play with that!

              But what you should do
               // Get and set placeholders   
              $var=$modx->getPlaceholder('placeholder_name');   
              $modx->setPlaceholder('placeholder_name', $var);   
              // Print placeholders in HTML
              [+placeholder_name+]

              http://blog.medianotions.de/en/articles/2008/modx-feature-api-cheat-sheet

                @hawproductions | http://mrhaw.com/

                Infograph: MODX Advanced Install in 7 steps:
                http://forums.modx.com/thread/96954/infograph-modx-advanced-install-in-7-steps

                Recap: Portland, OR (PDX) MODX CMS Meetup, Oct 6, 2015. US Bancorp Tower
                http://mrhaw.com/modx_portland_oregon_pdx_modx_cms_meetup_oct_2015_us_bancorp_tower
                • 13808
                • 61 Posts
                Awesome - ’save’ sounds like exactly the go - I’ll definitely have a play with that!

                Just to clarify, the code block mrhaw supplied would be used for grabbing and setting the values within the Snippet rather than passing content back in a return...?
                  • 3749
                  • 24,544 Posts
                  I have a suspicion that there’s a really simple way of accomplishing your overall goal. We’re kind of stumbling around because you haven’t ever described what you’re really trying to do. smiley

                  If you’re thinking of chunks and snippets "calling" each other, that could be part of your problem. What actually happens is that all MODx tags are replaced by what they refer to. So a chunk tag is just replaced by the contents of the chunk and a snippet tag in a chunk is replaced by the return value of the snippet.

                  Snippets, like Ditto, can set placeholders and placeholder tags are replaced by those settings values. The trick, as mentioned above, is to make sure the placeholders are set before the related tags are encountered in the processing. There’s a good description of the parsing order here (about 3/4 of the way down): http://www.sottwell.com/how-templates-work.html

                  If you’re not able to get things working based on the suggestions, try giving us a description of what you’re trying to do with a concrete example (leaving out any discussion snippets, TVs, or chunks).
                    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
                    • 13808
                    • 61 Posts
                    Very good call BobRay - thanks for picking me up there.

                    In a sentence, I’m looking to show what amounts to ’ads’ for pages in the site I’m building.

                    The way I’ve gone about this is to allow my client to create resources which contain two TVs - an image and a link (which they specify using [~#~] format).

                    Using ditto, I select these ads to be shown. The client isn’t using every graphic as a link though - they’re using some for information in which case the link field is left blank. I’d like to always output the image, but only output the <a> </a> tags around that image IF the link field is populated (so there’s nothing that looks like a link to the user, but then doesn’t go anywhere when clicked).

                    The TV names I’ve used are GraphicHighlight and GraphicLink.

                    Thank you all for your input - the level of support here is quite overwhelming! smiley
                      • 3749
                      • 24,544 Posts
                      Thanks! Thats much clearer.

                      If I’m understanding you, you shouldn’t need the link TV because Ditto will calculate it automatically and put it in the [+link+] placeholder (though it’s not hurting anything for now). You could change the link TV to ShowLink and make it a checkbox later. I don’t think you need a snippet either.

                      I think using PHX in your Ditto Tpl chunk would let you get the output you need.

                      I don’t use Ditto that much, but if you post your Ditto Tpl chunk, I’m sure someone can advise you.

                      I’m thinking something like this for displaying the two TVs as you describe (I’m used to the Revolution version of PHX so this probably won’t be quite right):

                      [+graphiclink:isnot=``:then=`<a href="[+graphiclink+]">[+graphicimage+]</a>`:else=`[+graphicimage+]`+]


                      If graphiclink goes to a checkbox, then the second reference to it would be changed to just [+link+].

                      Hope this makes sense.

                        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