We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 50312
    • 34 Posts
    Hi,
    I have a Multi Listbox TV which looks like this:

    TV [[*animals]]
    Panda==sweet-panda||Elephant==big-elephant||Duck==yellow-duck


    and I would like to create chunks from the TV output like this:

    [[$sweet-panda]]
    [[$big-elephant]]
    [[$yellow-duck]]


    Something like the following (which works), but with good code:

    Snippet-Call
    [[!getAnimalChunks? &tv=`[[*animals]]`]]

    Snippet
    <?php
    $array = explode(',', $tv);
    foreach($array as $var)
    {
        echo "[[$".$var."]]";
    }

    This question has been answered by Bruno17. See the first response.

    [ed. note: aaantz last edited this post 11 years, 5 months ago.]
      • 4172
      • 5,888 Posts
      why not

      Panda==[[$sweet-panda]]||Elephant==[[$big-elephant]]||Duck==[[$yellow-duck]]


      or use a MIGX-TV to manage them
        -------------------------------

        you can buy me a beer, if you like MIGX

        http://webcmsolutions.de/migx.html

        Thanks!
        • 50312
        • 34 Posts
        Because Lingua has a Problem with:

        Panda==[[$sweet-panda]]||Elephant==[[$big-elephant]]||Duck==[[$yellow-duck]]


        MIGX was one of my first thoughts - but I don't have it installed on that site and would only need it for that purpose.
        • discuss.answer
          • 4172
          • 5,888 Posts
          does it work this way?

          <?php
          
          $chunks = explode(',', $modx->getOption('tv', $scriptProperties, ''));
          
          $output = array();
          foreach ($chunks as $chunk) {
              $output[] = $modx->getChunk($chunk);
          }
          
          return implode('', $output);


            -------------------------------

            you can buy me a beer, if you like MIGX

            http://webcmsolutions.de/migx.html

            Thanks!
            • 50312
            • 34 Posts
            Yes, that works great! Thank you very much!