We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 33372
    • 1,611 Posts
    I have a simple snippet to loop through a TV value for a folder of documents and output them as a list sorted by the TV values. However I’ve run into an issue that caused me to look more closely at the output of getTemplateVarOutput, and I discovered that it just returns all of the values with no separators (no ’||’ or spaces or anything else). This is causing me some grief, and since it might do the same for others I recommend that an optional separator variable be added to the function in future releases.

    In my case, I have a bunch of member services as TV values. Two of these are "Marketing" and "Internet Marketing". Because there are no separators, I’m finding that any document with a value of "Internet Marketing" (but not "Marketing") is getting lumped in with the "Marketing" documents as well.

    I am using the following code to determine if a particular document has a particular service checked:
    if(strpos($memberTVs['services'],$thisService)!==FALSE){...output in here...}


    If there were separators I could search for those at the beginning and end of the particular value I’m looking for. But since there aren’t I don’t think I can use this API at all in this circumstance. Granted there are always other ways to get at the data, but the API is meant to make life easier...

    Is there anything I’m overlooking here, or am I right that this is an issue (with an easy resolution)?
      "Things are not what they appear to be; nor are they otherwise." - Buddha

      "Well, gee, Buddha - that wasn't very helpful..." - ZAP

      Useful MODx links: documentation | wiki | forum guidelines | bugs & requests | info you should include with your post | commercial support options
      • 25663 MODX Staff
      • 12,272 Posts
      This is a good find. Go ahead and open a bug on it if you would. Thanks.
        Ryan Thrash, MODX Co-Founder
        Follow me on Twitter at @rthrash or catch my occasional unofficial thoughts at thrash.me
        • 33372
        • 1,611 Posts
        So it’s not just me being thick-headed, then. Well that’s good news. I certainly have my numbskull moments.

        Bug opened here: http://modxcms.com/bugs/task/392

        Seems like a quick fix anyway.
          "Things are not what they appear to be; nor are they otherwise." - Buddha

          "Well, gee, Buddha - that wasn't very helpful..." - ZAP

          Useful MODx links: documentation | wiki | forum guidelines | bugs & requests | info you should include with your post | commercial support options
          • 6208
          • 44 Posts
          I agree this is problematic. The workaround I use is to include a comma in my TV assignment, i.e.:

          Chesapeake==Chesapeake,||Montego==Montego,||Biscayne==Biscayne,||ABEx2020==ABEx2020,||ABEx40XX==ABEx40XX,||Bayport==Bayport,||Mx-40==Mx40,||Lighthouse Tool Suite==lighthouse,||8040 ADM==8040adm,||8160 ADM==8160adm


          Then the returned values have commas I can separate on using an explode() call.
            • 26436
            • 19 Posts
            You may instead choose to use the Widget option below the values and set this to Delimiter with a comma. This is simply a trivial thing, but I personally have a problem adding a comma or additional separator to my values. You will still need to use explode() to separate the values, but works fairly well.
            example:
            TV
            Variable Name: ItemSizes
            Input Option Values: "size1==1||size2==2||size3==3"
            Widget: Delimited List Properties: Delimiter: ,

            Snippet
            $o = ’<select name="sizes">’;
            $vars = $modx->getTemplateVarOutput(’ItemSizes’, $id,’1’);
            $vary = explode(",",$vars[’ItemSizes’]);
            for($n=0;$n<sizeof($vary);$n++) {
            $o .= ’<option value="’.$vary[$n].’">’.$vary[$n].’</option>’;
            }
            $o.= ’</select>’;

            return $o;