We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 17775
    • 9 Posts
    I have a TV named MyTemplateVar with the HTML entities widget enabled. When I use this TV by itself, it parses htmlentities() properly. However, when I pass it to a Snippet, it disregards the Widget entirely.

    Is there a way to pass a Template Variable with Widgets to a Snippet?

    [!mySnippet? &sendString=`[*MyTemplateVar*]`!]


      • 28042 ☆ A M B ☆
      • 24,524 Posts
      No, because the snippet code fetches the raw value of the template variable. Well, I suppose the snippet in question could use a different API function to retrieve the formatted TV; the getTemplateVarOutput() function does that. http://wiki.modxcms.com/index.php/API:getTemplateVarOutput

      What you could do is create a snippet to replace the output widget (http://wiki.modxcms.com/index.php/Adding_TV_Widgets_without_hacking_the_core) then use that snippet (uncached) as the value for the parameter.
        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
        • 7455
        • 2,204 Posts
        [!mySnippet? &sendString=`[*MyTemplateVar*]`!]

        this should work
        first the tv is parsed and then its used in the snippet call.

          follow me on twitter: @dimmy01
          • 28042 ☆ A M B ☆
          • 24,524 Posts
          Hm. That’s correct. I was looking too deeply into the forest to see the tree!
            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
            • 17775
            • 9 Posts
            Quote from: Dimmy at Jul 08, 2010, 05:18 AM

            [!mySnippet? &sendString=`[*MyTemplateVar*]`!]

            this should work
            first the tv is pared and then its used in the snippet call.



            That’s my original code in the post above wink laugh The HTML entities values are not being returned properly.

            My [*MyTemplateVar*] has the content: " Some bad ! @ #* $( %) & and some more < > ";

            Then all [!mySnippet!] does is take the values and return them with html entities
            $output = "";
            
            function htmlEncode($sendString){
            $newVar = htmlentities($sendString);
            return $newVar;
            }
            $output = htmlEncode($sendString);
            
            return $output