We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 9549
    • 93 Posts
    I didn’t expect this to be that hard, but... it was smiley

    I have a TV called "fylke" which contains the input options:

    Ostfold==1||Aust-Agder==2||Buskerud==3||Finnmark==4||Hedmark==5||Hordaland==6||More og Romsdal==7||Nord-Trondelag==8||Nordland==9||Oppland==10||Oslo og Akerhus==11||Rogaland==12||Sor-Trondelag==13||Sogn og Fjordane==14||Svalbard==15||Telemark==16||Troms==17||Vest-Agder==18||Vestfold==19

    I have about 30 documents each containing the TV value (by their value, of course). Now I want to output the TV by it’s name and not their value, in the documents but also in the Ditto call listing them. Anyone? smiley

      • 18397
      • 3,250 Posts
      Here is a snippet that would do that:

      This assumes that the tv parameter is passed to it with the numeric value of the tv
      
      $tvData = explode("||",$tv)
      foreach ($tvData as $item) {
      $tvItem = explode("==",$item);
      if ($tvItem[1] == $tv) {
      return $tvItem[0];
      }
      }
      
      


      Note: code is not tested
        • 9549
        • 93 Posts
        Thanks, Mark. Could you please specify how I pass the Ditto tv parameter to the snippet?
          • 18397
          • 3,250 Posts
          [[snippetName?tv=`[+tvNameOfTV+]`]]

          Note the tv prefix.
            • 9549
            • 93 Posts
            My snippet (getFylkeName) looks like this:

            $tv = isset( $tv ) ? $tv : "";
            $tvData = explode("||",$tv);
            
            foreach ($tvData as $item) {
            $tvItem = explode("==",$item);
            if ($tvItem[1] == $tv) {
            return $tvItem[0];
            }
            }
            


            And I’m using this call [[getFylkeName?tv=`[+tvfylke+]`]]
            The TV is passed to the snippet correctly, but it outputs nothing when the snippet is parsed. sad