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

    i've got a comb single list template variable as :
    choice 1==1||choice 2==2||choice 3==3

    Some of resources used this tv, when I return the value, like, 1, 2 or 3, I would like to return the text associate with them, like "choice 1", "choice 2" or "choice 3", is there any api object to do it ?

    Thanks.
    Olivier.
      Low
      • 33968
      • 863 Posts
      Couldn't you just do this:
      choice 1||choice 2||choice 3
      


      Or do you need the integer values too?
        • 17546
        • 75 Posts
        Imagine this tv:

        tvExample (combo list) = "choice 1==1||choice 2==2||choice 3==3"

        In a resource, the tvExample is 2

        In the render template, I want to show this tv (the value) and not key, like "choice 2", and not 2

        With this format, I can add, or remove one or more 'choice', no care about the order of them, just the key, because it's the key who is recorded, not the value.

        Another question : how to return the content of a raw combo list, like my example "choice 1==1||choice 2==2||choice 3==3" with the modx api, just the row not the key recorded in a resource.

        Hope I explain good as well you can understand what I mean.

        Thanks.
        Olivier.
          Low
          • 37242 ☆ A M B ☆
          • 339 Posts
          Did you find a solution for this?
            • 17546
            • 75 Posts
            Hello,

            This is the output filter I did to do it :

            snippet name : type
            if(empty($options))return $input;
            parse_str($options, $z);
            $id = $z['id'];
            if(empty($id))return $input;
            $a = $modx->getObject('modTemplateVar', $id);
            $b = explode('||',$a->get('elements'));
            foreach($b as $key => $value):
            	list($text, $number) = explode('==',$value);
            	if($number==$input)return $text;
            endforeach;
            


            usage :
            [[+tvofcombo:type=`id=4`]]
            


            the id 4 number is the Id of the combo list resource.

            I hope it work for you like it was work for me.

            Olivier.
              Low