We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 45767
    • 13 Posts
    Hi Guys,
    Can't seem to find much on this topic of using a checkbox.

    Situation: I have a sidebar that can show a myriad of things, the usual information stuff. I want to allow to use to select which items will be shown on the sidebar. I can do this easily with setting each one to be its own checkbox, however it doesn't look great. So I decided to group them into 1 Checkbox themselves and then display whatever is checked.

    Setup:
    User End:


    TV Setup:


    Currently Tried:
    It seems when I call the [[*Sidebar]] TV it just lists out what has been checked. Great, I can work with that, however it's not in an array its literally a string with no way of exploding it out.

    I created a Snippet to take the TV and the current Page Id to determine what was checked.
    $parent = (int)$modx->getOption('parent', $scriptProperties, '');
    $tpl = $modx->getOption('tpl', $scriptProperties, 'sidebar_chunk');
    
    $page = $modx->getObject('modResource', $parent);
    print_r($page->getTVValue('Sidebar'));

    This does the same as just calling the TV so not much use there. After a bit more digging around I was getting close but I still feel I'm missing something

    $tv = $modx->getObject('modTemplateVar',array('name'=>'Sidebar'));
    
     
    $optionValues = $tv->get('elements');
    print_r($optionValues); 


    This prints out: Eurofilms TV||Collation Shrink||Film Optimization Chart||Form Fill and Seal||Packaging Audit||Pre Stretch Insight||Sample Audit Pack||Shrink Film
    Now on first look I got an instant coder's high thinking I had finally solved this problem, and then I looked again, it had just listed out everything when only 4 had been ticked. If it had printed out everything I.E. Eurofilms TV==1||Collation Shrink==0 I can work with explodes etc.

    I could be making a mountain out of a molehill here and potentially googling all the wrong keywords.

    I can see this being a really simple solution but I just can't seem to nail it.
    Any help would be appreciated.

    Thanks, Ross.

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

    • discuss.answer
      • 22427
      • 793 Posts
      At first glance I think the syntax you use for the Default Value is not correct.

      Apart from this: If in the Output Options of the TV you set Output Type to Delimiter and set a delimiter of your choice (f.i. #), then the TV would output the string
      Eurofilms TV#Collation Shrink#Form Fill and Seal#Pre Stretch Insight
      (containing just the options you checked).

      Then you just need a snippet to explode this string into an array (or to create the output in any other way you like).
        • 4172
        • 5,888 Posts
        if this are chunks, you can have input-options like:

        Eurofilms TV==[[$Eurofilms]]||Collation Shrink==[[$Collation Shrink]]||Film Optimization Chart==[[$Film Optimization Chart]]||Form Fill and Seal==[[$Form Fill and Seal]]||Packaging Audit==[[$Packaging Audit]]||Pre Stretch Insight==[[$Pre Stretch Insight]]||Sample Audit Pack==[[$Sample Audit Pack]]||Shrink Film==[[$Shrink Film]]
          -------------------------------

          you can buy me a beer, if you like MIGX

          http://webcmsolutions.de/migx.html

          Thanks!
          • 43851
          • 21 Posts
          I use this method all the time for slecting chunks to display, it works a treat: http://wiki.modxcms.com/index.php/Create_TV-Based_Chunks#Chunk_List_Parser
            • 45767
            • 13 Posts
            Cheers Guys, got it working perfectly with a little bit of magic from @webo880 and @ottogal mixed together.

            Knew I was missing something simple smiley