We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 36760
    • 136 Posts
    I'm trying to set up an if/then/else type statement in an MIGX tpl to show images and images with links (when a URL is present).

    So far, using the below line in my tpl file, the image is only displayed if a URL is present. I would like the image to display (with out the anchor tags) when a URL isn't present. I've tried a few different things, but this is what's gotten me the closest.

    [[+url:if=`[[+url]]`:eq=``:then=`<img src="[[+image]]" alt="" />`:else=`<a href="[[+url]]"><img src="[[+image]]" alt="" /></a>`]]


    Thanks for any help! [ed. note: firebot6 last edited this post 12 years ago.]
      • 34073
      • 34 Posts
      I use the If extension. Something like this:

      [[!If?
        &subject=`[[+url]]`
        &operator=`isempty`
        &then=`<img src="[[+image]] atl="" />`
        &else=`<a href="[[+url]]"><img src="[[+image]]" alt="" /></a>`
      ]]
      
        • 36760
        • 136 Posts
        I think that worked. Now when the URL is empty, I can see the image in the source code. It just doesn't show in the slider unless I have something entered in the URL box. So I think it's an issue with the slider at this point.

        Thanks for your help!
          • 14951
          • 151 Posts
          A little late, but why use the "If" snippet?

          This could easily be done like this:
          [[+url:notempty=`<a href="[[+url]]">`]]<img src="[[+image]]" alt="" />[[+url:notempty=`</a>`]]


          Less code and probably faster..
            • 34073
            • 34 Posts
            We agree that element modifiers are usually the better way to go, but in our case when we used them we had the following scenario:
            When not true it would work fine and not render the links around the image. But when the condition of not empty was true, the value of the tv is rendered rather than <a href="[[+url]]"> or </a>.
            When we switched to using the If snippet for this case, it worked perfectly.
              • 36760
              • 136 Posts
              When using the If plugin (or the modifiers, whichever would work best), is there a way to show/hide a section of code that contains the MIGX call depending on if anything is entered for that particular TV? I tried something like this, but with no luck:

                          
                        [[If?
                              &subject=`[[*latestNews]]`
                              &operator=`isempty`
                              &then=``
                              &else=`
                                  <div class="latest-news">
                                      <h2>Latest News</h2>
                                      [[!getImageList? &tvname=`latestNews` &tpl=`latestNewsTpl`]]
                                      <div class="latest-news-btm"></div>
                                   </div>
                                    `
                           ]]
              


              I wasn't sure if this was best here, or in another area, but thought since this thread was going it may fit here!

                • 34073
                • 34 Posts
                Yes, we do this. For example:

                [[!If?
                  &subject=`[[*sponsors]]`
                  &operator=`isnotempty`
                  &then=`[[$sponsorslist]]`
                ]]
                


                sponsorlist is a chunk with a MIGX call in it. So I would try a chunk with the code in it rather than just the straight code in it. Also, you don't need the else, you just need the then with a chunk call. Trying the if or element modifier cached or uncached is a good idea. So something like:

                [[!If?
                  &subject=`[[*latestNews]]`
                  &operator=`isempty`
                  &then=`[[$showlatestnews]]`
                ]]
                

                  • 36760
                  • 136 Posts
                  Thanks for the help.

                  When I use your example, it still doesn't work as I'd expect.

                  [[!If?
                  &subject=`[[*latestNews]]`
                  &operator=`isempty`
                  &then=`[[$latestNewsMIGX]]`
                  ]]

                  The above doesn't display anything, whether there's data in MIGX or not.


                  [[!If?
                  &subject=`[[*latestNews]]`
                  &operator=`isnotempty`
                  &then=`[[$latestNewsMIGX]]`
                  ]]

                  And this one displays something no matter what (either just my sidebar title/background, or the title/background plus MIGX content when there is some).

                  I've tried the calls cached/un-chached, and with clearing the Modx cache and my browser cache.

                  Is it possible that MIGX is passing something along not matter what? Even if it isn't actual displayed content.
                    • 4172
                    • 5,888 Posts
                    Do you get something with
                     [[*latestNews]]


                    you can also try
                    [[getImageList? &tvname=`latestNews` &tpl=`latestNewsTpl` &toPlaceholder=`migxoutput`]]
                    
                    [[+migxoutput:isnot=``:then=`
                    <div class="latest-news">
                    <h2>Latest News</h2>
                    [[+migxoutput]]
                    <div class="latest-news-btm"></div>
                    </div>
                    `:else=``]]
                    
                    
                      -------------------------------

                      you can buy me a beer, if you like MIGX

                      http://webcmsolutions.de/migx.html

                      Thanks!