We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 37165
    • 89 Posts
    I'm using migxdb for a complex gallery system I've named artGallery. I have set up numerous multi-select list tvs that feed into my artGallery. For example I have a tv named "color" that has the following multi-select options.

    yellow||blue||green||red||yellow, etc

    In artGallery some images have a value of just "yellow" while others may have "yellow||blue"

    If there is just one value I'd like an output that looks like this when there is one value:

    <li<a href="yellow.html">yellow</a></li>
    


    and like this when there are two values:

    <li<a href="yellow.html">yellow</a></li><li<a href="blue.html">Blue</a></li>
    


    My chunk works fine with one value but with two value I get this:
    <li<a href="yellow||blue.html">yellow||blue</a>
    


    This makes sense when you see the chunk code:
    						<div class="relatedGalleries">Related Galleries</div>	
    				
    						<ul>
    							
    							<li class="archiveButton" id="[[+project]]"><a href="[[+project]].html">[[+project]]</a></li>
    							
    							<li class="archiveButton" id="[[+year]]"><a href="[[+year]].html">[[+year]]</a></li>
    				
    							<li class="archiveButton" id="[[+color]]"><a href="[[+color]].html">[[+color]]</a></li>
    							
    							<li class="archiveButton" id="[[+media]]"><a href="[[+media]].html">[[+media]]</a></li>				
    				
    						</ul>


    My is how to I get the [[+color]] placeholder to template itself out as different chunks if there are two values?

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

      • 4172
      • 5,888 Posts
      try it like that:

      snippet loopDelimited:

      $delimiter = $modx->getOption('delimiter',$scriptProperties,',');
      $value = $modx->getOption('value',$scriptProperties,'');
      $tpl = $modx->getOption('tpl',$scriptProperties,'');
      $outputSeparator = $modx->getOption('outputSeparator',$scriptProperties,"\n");
      
      $values = explode($delimiter,$value);
      $idx = 1;
      foreach ($values as $value){
          $item = array();
          $item['value'] = $value;
          $item['_idx'] = $idx;
          $output[] = $modx->getChunk('tpl',$item);
          $idx++;
      }
      
      return implode($outputSeparator,$output);


      [[loopDelimited? &value=`[[+color]]` &delimiter=`||` &tpl=`colorTpl`]]


      colorTpl:

      <li<a href="[[+value]].html">[[+value]]</a></li>



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

        you can buy me a beer, if you like MIGX

        http://webcmsolutions.de/migx.html

        Thanks!
        • 37165
        • 89 Posts
        Hi Bruno, thanks for your help. I tried the above solution but it didn't produce anything. Was a blank output.

        I made the snippet, Put the snippet call inside my migxdb template, and saved the colorTPL as a chunk. Is there something I'm missing?
        • discuss.answer
          • 4172
          • 5,888 Posts
          this line was wrong:
          $output[] = $modx->getChunk('tpl',$item);


          $delimiter = $modx->getOption('delimiter',$scriptProperties,',');
          $value = $modx->getOption('value',$scriptProperties,'');
          $tpl = $modx->getOption('tpl',$scriptProperties,'');
          $outputSeparator = $modx->getOption('outputSeparator',$scriptProperties,"\n");
           
          $values = explode($delimiter,$value);
          $idx = 1;
          foreach ($values as $value){
              $item = array();
              $item['value'] = $value;
              $item['_idx'] = $idx;
              $output[] = $modx->getChunk($tpl,$item);
              $idx++;
          }
           
          return implode($outputSeparator,$output);
            -------------------------------

            you can buy me a beer, if you like MIGX

            http://webcmsolutions.de/migx.html

            Thanks!
            • 37165
            • 89 Posts
            Thanks so much, this works perfectly.