We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 27330
    • 884 Posts
    Hello everyone,
    I'm trying to display an unordered list from a comma separated Text TV.
    I found similar post here, but I think it was coded for Evo. would appreciate any help.
    The idea is that a manager user can add Red,White,Blue in the TV and the output source will be

    <ul>
    <li>Red</li>
    <li>White</li>
    <li>Blue</li>
    </ul>
    



    This is what I tried so far:
    created a Text input TV, output default. [[*WallOptionFeatures]]

    Then I created the snippet called [[wallOptionFeaturesList]] with this code:

    <?php
    $id = (isset($id))? $id : $modx->documentIdentifier;
    $tvName = (isset($tvName))? $tvName : 'WallOptionFeatures';
    $output = '';
    $data = $modx->getTemplateVarOutput(true, $id);
    $tv = $data[''.$tvName.''];
    if (!empty($tv)) {
    $values = explode(',', $tv);
    $output = "\n <ul>";
    foreach($values as $value) {
         $output .= "\n"  .  '    <li>' . $value . '</li>';
    }
    $output = "\n<ul>";
    }
    return $output;
    


    and called the snippet on the page.
    The result was blank page.
    I tried cached/uncached or calling the snippet inside a chunk with no luck. always blank page. When called the snippet from within a chunk the actual snippet call was displayed, not the expected output...
    Would anyone be kind to help?
    Thank you.

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

    • discuss.answer
      • 4172
      • 5,888 Posts
      for Revo you can try it this way:

      <?php
      
      $id = (isset($id)) ? $id : $modx->resource->get('id');
      $tvName = (isset($tvName)) ? $tvName : 'WallOptionFeatures';
      $output = '';
      if ($resource = $modx->getObject('modResource', $id)) {
          $tv = $resource->getTVValue($tvName);
          if (!empty($tv)) {
              $values = explode(',', $tv);
              $output = "\n <ul>";
              foreach ($values as $value) {
                  $output .= "\n" . '    <li>' . $value . '</li>';
              }
              $output .= "\n</ul>";
          }
      }
      
      return $output;
      
      
      [ed. note: Bruno17 last edited this post 11 years ago.]
        -------------------------------

        you can buy me a beer, if you like MIGX

        http://webcmsolutions.de/migx.html

        Thanks!
        • 27330
        • 884 Posts
        Thanks Bruno, but this only prints me the <ul> tag with nothing below it.
        like so:

        <html>
        <head>
        <title></title>
        <base href="" />
        </head>
        <body>
        
        <ul>
        </body>
        </html>
        


        mind looking again?
          • 4172
          • 5,888 Posts
          fixed this line:

          $output .= "\n</ul>";


          does it work now?

          not sure, if it is coming out as commaseperated list.
          you can test that by

          echo $tv;




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

            you can buy me a beer, if you like MIGX

            http://webcmsolutions.de/migx.html

            Thanks!
            • 27330
            • 884 Posts
            Thanks a lot. you are my hero. works perfect!