We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 17578
    • 33 Posts
    Hi All,

    I'm building a site with multiple content categories in which I'm trying to use a single check box TV with multiple values to filter pages and page content throughout the site. It would be great if I can reuse the same, single check box TV on multiple page templates so as to consolidate the site building, and eventual administration process. The TV is set up more or less as follows:

    Input Options=Check Box

    Input Option Values: Box1==val1||Box2==val2||Box3==val3||box4==val4||Box5==val5

    Output Options > Output Type: Delimiter - with a comma in the field.

    This TV works perfectly using TVfilters in my getResources calls. What I can't seem to figure out is how to display something on a resource (HTML page) that uses the check box TV in the template.

    For example: I have a template with a chunk with the check box TV in it. The chunk has only [[*checkboxTV]] in it right now. If I check boxes 1 and 3 in a resource it displays <ul>val1,val3</ul> in the HTML page. What I'm trying to figure out is if I can get the chunk, or template to display a different image for each box checked (something like <li><a href="#"><img src="image" /></a></li>). So if there are no boxes checked no images. If 3, then 3 different images based on the boxed check. Can the check box TV do this? I'm stumped right now as to how.

    This site is using Modx 2.2.6 Traditional. PHP 5

    Thanks for any insight.

    R
      • 4172
      • 5,888 Posts
      Here's one of a ton of ways.
      you can try a snippet like this:

      <?php
      
      //[[renderList? &input=`[[*yourCommaTV]]` &tpl=`yourTplChunk`]]
      
      $outputSeparator = $modx->getOption('outputSeparator',$scriptProperties,'');
      $input = $modx->getOption('input',$scriptProperties,'');
      $inputs = explode (',',$input);
      
      foreach ($inputs as $value){
          $properties['value'] = $value;
          $output[] = $modx->getChunk($tpl,$properties);
      }
      
      return implode($outputSeparator,$output);


      call it like that:

      [[renderList? &input=`[[*yourCommaTV]]` &tpl=`yourTplChunk`]]


      with a tplChunk like this:

      <img scr="[[+value]].jpg" />


      may be MIGX would be something for you.

      its also possible to have inputoptions like this, if you want to out some chunks:

      box1==[[$box1]]||box2==[[$box2]]||box3==[[$box3]]







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

        you can buy me a beer, if you like MIGX

        http://webcmsolutions.de/migx.html

        Thanks!
        • 17578
        • 33 Posts
        Thanks Bruno.

        I have used MIGX with another install an it was awesome. Your last suggestion, using a chunk as the value for the checked box did the trick. And it did not break my getResources filtering. Your first snippet was probably more than I needed, but thanks. I basically was trying to figure out a way that if checkbox x, y or z was checked display this image x,y or z in the page.

        I was trying to use the IF add-on or just the built in MODX TV filtering without having to use a snippet. Is that possible?

        Again, thanks.