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

    i have 3 different out puts depending on if some TV are populated and wondered if its possible to do an else if. So basically i have:

    TV-1
    TV-2
    TV3

    IF TV-1 is empty do this,
    ELSEIF TV-2 is empty do this
    ELSE do this.

    Any suggestions, i've tried nesting the filters, i've tried nesting the IF snippet and i've tried a combo of the two. But no luck.

    I've also looked at the switch snippet which doesn't look like it will work in my case.

    Thanks in advance

    B
      • 28215
      • 4,149 Posts
      [[*tv1:empty=`[[*tv2:empty=`[[*tv3]]`]]`]]
      
        shaun mccormick | bigcommerce mgr of software engineering, former modx co-architect | github | splittingred.com
        • 36926
        • 701 Posts
        Thanks splittingred for your help, the only problem i have here is i don't want to just render out just the tv value. So depending on which one is empty.

        Probably better to use my actual situation as reading my first post i wasn't that clear.

        I have 3 tvs.
        TV1 contains a video path,
        TV2 contains an image path
        TV3 contains a description for the image

        IF there's video(tv1) then render the html but if no video then check if a description(tv3) has been added. If there is a description then render the image html with the description html if not just render the image.

        I was hoping just to nest some if calls. Oh also this is within a getResoure tpl. This is what i had tried.
        
        [[+tv.videoPath:if=`[[+tv.videoPath]]`:eq=``:then=`[[+tv.hoverText:if=`[[+tv.hoverText]]`:eq=``:then=`MAGE no description`:else:=`IMAGE with description`]]`:else=`VIDEO`]]
        
        


        it renders a video correctly, but images are all rendered as image with description.

        Thanks

        B
          • 36926
          • 701 Posts
          Ok i decided to see if i could write a snippet that could deal with this and it seems to be doing the trick.

          I created a snippet called "areYouAVideo" with the following code


          <?php
          if ($videoSrc == '') {
          	if ($hoverText == ''){
             		$output = "IMAGE";
          	} else {
          		$output = "HOVER";
          	}
          }
          else {
             $output = "VIDEO";
          }
          
          return $output;
          ?>


          Then used this call in my getResource template passing in the two TVs i want to check against if they had values. The call

          [[areYouAVideo? &videoSrc=`[[+tv.videoPath]]` &hoverText=`[[+tv.hoverText]]` ]]
          


          Not sure if this is the best way to do it, but it works.

          Ben
            • 4172
            • 5,888 Posts
            In this case I would create a custom snippet with something like that:

            <?php
            if (!empty($videoPath)){
                return $videoOut;
            }
            if (!empty($hoverText)){
                return $hoverOut;
            }
            return $default;


            and call it this way:

            [[mysnippet?
            &videoPath=`[[+tv.videoPath]]`
            &hoverText =`[[+tv.hoverText]]`
            &videoOut=`[[+tv.videoPath]]`
            &hoverOut=`IMAGE with description`
            &default=`IMAGE no description`
            ]]
              -------------------------------

              you can buy me a beer, if you like MIGX

              http://webcmsolutions.de/migx.html

              Thanks!
              • 36926
              • 701 Posts
              Thanks Bruno, that works much better than mine. I was have some issues with placeholders displaying the same image for the else statement.

              But no such problems with your snippet, thanks again.

              Ben
              • Can we wake a sleeping thread?

                I'm trying to create a nested output modifier like:
                [[*tv1:notempty=`[[$DisplayChunkOne]]`:else=`[[*tv2:notempty=`[[$DisplayChunkTwo]]`:else=``]]`]]


                Kindly look at this to see what's wrong cause right now nothing is displayed.
                  • 3749
                  • 24,544 Posts
                  How about a snippet?

                  [[!DisplayChunk? &chunkOne=`SomeChunk` &chunkTwo=`SomeOtherChunk`]]



                  /* DisplayChunk snippet */
                  
                  $chunk1 = $modx->getOption('chunkOne', $scriptProperties, 'No Chunk1');
                  $chunk2 = $modx->getOption('chunkTwo', $scriptProperties, 'No Chunk2');
                  $tv1 = $modx->resource->getTVValue('TV1');
                  $tv2 = $modx->resource->getTVValue('TV2');
                  $output='';
                  
                  if (!empty($tv1)) {
                      $output = $modx->getChunk($chunk1);
                  } elseif (!empty($tv2)) {
                      $output = $modx->getChunk($chunk2);
                  }
                  
                  return $output;


                  This assumes that they are always the same two TVs. If not the TV names or IDs could be sent as properties.
                    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
                  • Yes the chunks and TVs will always be the same.

                    I've tried this but no output. The call [[!DisplayChunk? &chunkOne=`[[$Banner400H]]` &chunkTwo=`[[$Banner400H_wSlideshow]]`]] was placed in a template.

                    Since there are several TVs on the resource, I supplied the actual names of the TV: I think there is difficulty recognizing the TVs. [ed. note: ojchris last edited this post 9 years, 11 months ago.]
                      • 3749
                      • 24,544 Posts
                      In the &chunkOne and &chunkTwo properties, you want the *name* of the chunk, not a tag for it:

                      [[!DisplayChunk? &chunkOne=`Banner400H` &chunkTwo=`Banner400H_wSlideshow`]] 
                        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