We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 10313
    • 375 Posts
    Hello!

    I’m using Ditto 2.0.2 with &tpl=`teaserXT` (my own chunk).

    teaserXT is
    <div class="ditto_item" id="ditto_item_[+id+]">
    [[showPreviewXT? &spvImageName=`[+teaserBild+]` &flash=`[+teaserFlash+]` &introText=`[+introtext+]` &nurBild=`[+nurBild+]` &kategorie=`[+kategorie+]` &flashW=`[+flashWidth+]` &flashH=`[+flashHeight+]`]]
    </div><br/>
    


    As you can see, I’m calling my own snippet showPreviewXT wich generates the HTML depending on some of the given parameters. [+introtext+] is the standard [*introtext*] document variable. All others are TVs.

    The problem is: The snippet receives wrong values for the parameters:

    a) if the string conatins a "?", it is omitted. It’s just not there. "Hello? There." becomes "Hello There".
    b) if the string contains a "&", the value is cut at the second last character before the "&", wich means: an original value of "hans&franz" will become "han" in the snippet.

    What’s wrong here? Thanks for any tipps
    Martin
      • 28042 ☆ A M B ☆
      • 24,524 Posts
      A snippet parameter cannot contain those characters; they are parameter delimiters. When the placeholder is parsed, that string becomes a parameter of your snippet call and those characters are parsed again accordingly.
        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
        • 10313
        • 375 Posts
        Wich could be very useful if i need it. Hm, can I mask these characters?

        Thanks for the prompt answer
        Martin
          • 28042 ☆ A M B ☆
          • 24,524 Posts
          Not sure if there is a better way, but when I ran across something similar I created a "wrapper" snippet, to call my snippet using
          $modx->runSnippet("snippetName", array('snippetParam1'=>'value1', 'snippetParam2'=>'value2')) 

          which took care of the delimiter character issue if one of the parameters used those characters.
            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
            • 10313
            • 375 Posts
            But then, I would have give the parameters with the delimiter characters to the wrapper snippet. How could I do that? If there would be an easy way to get the TVs for a given document ID within a snippet, it all would be no problem. I once read that

            $modx->getDocument($ID) (which hopefully returns a complete documentObject) should not be used by snippets.

            Martin
              • 28042 ☆ A M B ☆
              • 24,524 Posts
              Well, I’ve gone as far as I can, hopefully soon somebody better at this than I am will have a better answer for you.
                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
                • 10313
                • 375 Posts
                Thank you very much, Susan smiley
                  • 19726
                  • 239 Posts
                  I would pass the pageid to the showPreviewXT snippet and then in the snippet get the tv’s and fields. You could code your own field/tv retrieval functions if nothing is available in the MODx API or you could call the GetField snippet (it’s in the repository) from code to get the content of the fields/TV’s.
                    • 22303 MODX Staff
                    • 10,725 Posts
                    $modx->getTemplateVar() and $modx->getTemplateVarOutput() is what you are looking for.