We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 47401
    • 295 Posts
    its currently outputting:

    <ul>
    <li id="key0">1</li>
    <li id="key1">2</li>
    <li id="key2">5</li>
    </ul>
      • 47401
      • 295 Posts
      Ok Guys, thanks for your help. I managed to create a snippet with the following in, which worked for me. let me explain what I did:

      Created a TV called GetFacilities, input as checkbox, output as delimiter using value ,

      When calling the GetFacilities snippet ensured the opening and closing ul tags are around the snippet.

      My snippet code is:

      $output = '';
      $tv = $modx->getObject('modTemplateVar',array('name'=>"Facilities"));
      // retreives the full array key->value of the TV
      $options = explode('||',$tv->get('elements'));
      $id = $modx->resource->get('id');
      $page = $modx->getObject('modResource', $id);
      $tv = $page->getTVValue('Facilities');
      // outputs into an array only the keys (checkboxes that are selected only against that document)
      $tvarray = explode(',', $tv);
      // loops through the array which only contains each of our selected checkboxes
      foreach($tvarray AS $option) {
      // loops and checks if the key against the full list in $otions exists, if it does exist, appends to $output
      if(isset($options[$option])) {
      $value = $options[$option];
      $output .= "<li>".$value."</li>";
      }
      }
      // the end result, only showing values of the checkbox that has been selected against that document
      return $output;


      Hopefully this should help somebody else out an it took me awhile to understand it.
        • 50574
        • 70 Posts
        Could you just put the output <li> directly in the input options of the TV?
        I did this recently to achieve the same effect (a list of product bullet points).
        Rooms with En Suite==<li>Rooms with a Suite</li>||Heated Indoor Swimming Pool==<li>Heated Indoor Swimming Pool</li>||Sauna==<li>Sauna</li>||Exercise Studio==<li>Exercise Studio</li>||Treatment Room==<li>Treatment Room</li>||Outdoor Swimming Pool==<li>Outdoor Swimming Pool</li>

        and then, like Susan said, call the TV inside the <ul>
        <ul>[[*Facilities]]</ul>
          • 28042 ☆ A M B ☆
          • 24,524 Posts
          You get the same thing with an output type of "HTML Tag" and setting the Tag Name to li.
            Studying MODX in the desert - http://sottwell.com
            Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
            Join the Slack Community - http://modx.org
            • 47401
            • 295 Posts
            Quote from: sottwell at Dec 04, 2015, 05:22 AM
            You get the same thing with an output type of "HTML Tag" and setting the Tag Name to li.

            problem with HTML tag is that it only produces the key and not the value in the list. so by retreiving the array, it gives me more control over how and what I need to do with the data wink
              • 28042 ☆ A M B ☆
              • 24,524 Posts
              I had this pointed out to me on Slack
              This part (getTVLabel) of the ToggleTVSet Package would show the label (key) of the according TV value in a TV with input options: http://jako.github.io/ToggleTVSet/#output-filter
                Studying MODX in the desert - http://sottwell.com
                Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
                Join the Slack Community - http://modx.org
                • 47401
                • 295 Posts
                Quote from: sottwell at Dec 04, 2015, 07:30 AM
                I had this pointed out to me on Slack
                This part (getTVLabel) of the ToggleTVSet Package would show the label (key) of the according TV value in a TV with input options: http://jako.github.io/ToggleTVSet/#output-filter

                Ok great thanks for you input.

                Matt