We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 3749
    • 24,544 Posts
    You could leave it as you had it but rather than testing for empty, test for whatever is in the TV when it's empty (do a "View Source" to see what's there). Something like this:

    [[[[*TVname:isequalto=`<li></li>` &then=``  &else=`$categoryChunk`]]]] 



    A custom snippet, though, is always much faster, you can make it straight text TV and use comma delimiters, then process it any way you want in the snippet. Here's an example:

    [[!ShowMyTv]]


    /* ShowMyTV snippet */
    
    $tv = $modx->resource->getTVValue('MyTV');
    if (empty($tv)) {
        return '';
    }
    
    $tvArray = explode(",", $tv);
    $output = '<ul class="whatever">';
    
    foreach($tvArray as $item) {
       $output .= "\n    <li>" . $item . "</li>";
    }
    $output .= "\n</ul>"
    return $output;
    

    [ed. note: BobRay last edited this post 11 years, 7 months ago.]
      Did I help you? Buy me a beer
      Get my Book: MODX:The Official Guide
      MODX info for everyone: http://bobsguides.com/modx.html
      My MODX Extras
      Bob's Guides is now hosted at A2 MODX Hosting
      • 19872
      • 1,078 Posts
      Bob! Thank you! On my way back from the store just now, I was thinking I needed to get the output modified to recognize and act on the <li></li> but I had no idea of the proper way to write it.
        • 3749
        • 24,544 Posts
        Don't thank me until it works. wink
          Did I help you? Buy me a beer
          Get my Book: MODX:The Official Guide
          MODX info for everyone: http://bobsguides.com/modx.html
          My MODX Extras
          Bob's Guides is now hosted at A2 MODX Hosting
          • 19872
          • 1,078 Posts
          Quote from: BobRay at Feb 20, 2015, 09:06 PM
          You could leave it as you had it but rather than testing for empty, test for whatever is in the TV when it's empty (do a "View Source" to see what's there). Something like this:

          [[[[*TVname:isequalto=`<li></li>` &then=``  &else=`$categoryChunk`]]]] 


          I started with the above approach. No luck. Nothing loads regardless of whether or not items are checked.

          I do notice that you and Susan put your brackets on the very outer edges, but the docs have them tucked around each TV or Chunk. Are the docs wrong, or are there just multiple ways of writing it out?

          I think I need to stop fighting with the TV output of HTML tag li, change it to default or delimited and try your snippet approach. Got my day cut out for me I guess.:)
            • 19872
            • 1,078 Posts
            Quote from: BobRay at Feb 20, 2015, 09:06 PM



            A custom snippet, though, is always much faster, you can make it straight text TV and use comma delimiters, then process it any way you want in the snippet. Here's an example:

            [[!ShowMyTv]]


            /* ShowMyTV snippet */
            
            $tv = $modx->resource->getTVValue('MyTV');
            if (empty($tv)) {
                return '';
            }
            
            $tvArray = explode(",", $tv);
            $output = '<ul class="whatever">';
            
            foreach($tvArray as $item) {
               $output .= "\n    <li>" . $item . </li>
            }
            $output .= "\n</ul>"
            return $output;
            


            I've modified it slightly, but getting syntax error, unexpected '<' around line 13 – I can't tell what line 13 is but think it to be around where the n li $item is located. I don't understand why the double quotes are put only around the backslash n li.
            Seems like that whole phrase should be within double quotes, but when I do that, the error changes to line 14 unexpected }

            Need to jump back over to my tutorials at Lynda.com. I understand a tiny fraction of what I need to do this.

            /* ShowFeatures snippet Display Interior Features */
             
            $tv = $modx->resource->getTVValue('propFeature_Interior');
            if (empty($tv)) {
                return '';
            }
             
            $tvArray = explode(",", $tv);
            $output = '<h5>Interior</h5><ul class="no-bullet">';
             
            foreach($tvArray as $item) {
               $output .= "\n    <li>" . $item . </li>
            }
            $output .= "\n</ul>"
            return $output;
            • discuss.answer
              • 4172
              • 5,888 Posts
              try this:

              <?php
              
              /* ShowFeatures snippet Display Interior Features */
                
              $tv = $modx->resource->getTVValue('propFeature_Interior');
              if (empty($tv)) {
                  return '';
              }
                
              $tvArray = explode(",", $tv);
              $output = '<h5>Interior</h5><ul class="no-bullet">';
                
              foreach($tvArray as $item) {
                 $output .= "\n    <li>" . $item . "</li>";
              }
              $output .= "\n</ul>";
              return $output;
              
                -------------------------------

                you can buy me a beer, if you like MIGX

                http://webcmsolutions.de/migx.html

                Thanks!
                • 4172
                • 5,888 Posts
                Quote from: mmcgee at Feb 21, 2015, 10:37 AM


                I do notice that you and Susan put your brackets on the very outer edges, but the docs have them tucked around each TV or Chunk. Are the docs wrong, or are there just multiple ways of writing it out?


                This syntax does change the parsing - order and does parse the content of the chunk, only it the result of the output - filter matches.
                Otherwise it would parse the chunk and its content in any case, just wouldn't output it.
                See also:

                http://modx.com/blog/2012/09/14/tags-as-the-result-or-how-conditionals-are-like-mosquitoes/
                  -------------------------------

                  you can buy me a beer, if you like MIGX

                  http://webcmsolutions.de/migx.html

                  Thanks!
                  • 19872
                  • 1,078 Posts
                  Thanks Bruno: That works! Thanks for the link to the article–getting ready to read it now.
                  Is this a day when I learn something new, or just realize how much I don't know? I'll remain optimistic state of denial and consider that I have learned something new.:)

                  I did many of the Lynda.com PHP tutorials—a tsunami of information. Need to do more php more often so as to retain it.

                  Thank you!
                    • 19872
                    • 1,078 Posts
                    I know this type of thing is elementary to most here, but I feel as though I've struck gold. Would this be an OK way to write the snippet if I want the contents of a Text TV to display only if if contains some text or number?

                    I modified the snippet from the previous task so that if a number is entered in my fireplaceQuantity TV, the result will be displayed on the web page. If nothing is entered, nothing displays.



                    <?php
                    /* Snippet to Display Number of Fireplaces */
                       
                    $tv = $modx->resource->getTVValue('fireplaceQty');
                    if (empty($tv)) {
                        return '';
                    }
                    
                    $output = '<li><smalllabel>FIREPLACE:</smalllabel> [[*fireplaceQty]]</li>';
                    
                    return $output;
                      • 4172
                      • 5,888 Posts
                      This is looking good.
                      You could make it a bit more reusable by adding a tpl and tvname - property

                      <?php
                      
                      /* Snippet to Display Number of Fireplaces */
                      $tvname = $modx->getOption('tvname', $scriptProperties, '');
                      $tpl = $modx->getOption('tpl', $scriptProperties, '');
                      
                      $output = '';
                      if (!empty($tvname) && !empty($tpl)) {
                          $tv = $modx->resource->getTVValue($tvname);
                          if (!empty($tv)) {
                              $output = str_replace('[[+value]]', $tv, $tpl);
                          }
                      }
                      
                      return $output;


                      and call it with that properties:

                      &tvname=`fireplaceQty`
                      &tpl=`<li><smalllabel>FIREPLACE:</smalllabel>[[+value]] </li>`
                      
                      [ed. note: Bruno17 last edited this post 11 years, 7 months ago.]
                        -------------------------------

                        you can buy me a beer, if you like MIGX

                        http://webcmsolutions.de/migx.html

                        Thanks!