We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 48853
    • 12 Posts
    Hi, i looking for way how to use IF condition ELSE conditions inside getImageList

    My chunk code for slider item:
        <div id="slider-main">
            <ul class="bjqs">
            [[!getImageList? 
            &tvname=`slider_main`
            &tpl=`@CODE:
                <li>
                    <a href="[[+url]]" title="[[+text]]">
                        <img src="[[+image]]" alt="" />
                    </a>
                </li>
            `]]
            </ul>
        </div>

    I need write condition for forming output of li item layout depending from [[+url]].
    E.g. If [[+url]] is not empty:
                <li>
                    <a href="[[+url]]" title="[[+text]]">
                        <img src="[[+image]]" alt="" />
                    </a>
                </li>

    else if [[+url]] is empty:
                <li>
                        <img src="[[+image]]" alt="" />
                </li>

    Already read http://rtfm.modx.com/extras/revo/if but i think this is not for my case.

    Will be appreciate for help.

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

    • discuss.answer
      • 30912
      • 463 Posts
      If will work for this but youll need to do it in a template rather than @code

      imageTpl

      
      [[If? 
      &subject =`[[+url]]` 
      &operator=`isempty`
      &then=`
      <li>
              <img src="[[+image]]" alt="" />
      </li>`
      &else=`
      <li>
                  <a href="[[+url]]" title="[[+text]]">
                      <img src="[[+image]]" alt="" />
                  </a>
      </li>`
      ]]
      
      


      Should work no issue.

      Hope it helps.
        • 48853
        • 12 Posts
        Quote from: Tyreal2012 at Oct 16, 2014, 10:51 AM
        If will work for this but youll need to do it in a template rather than @code

        imageTpl

        
        [[If? 
        &subject =`[[+url]]` 
        &operator=`isempty`
        &then=`
        <li>
                <img src="[[+image]]" alt="">
        </li>`
        &else=`
        <li>
                    <a href="[[+url]]" title="[[+text]]">
                        <img src="[[+image]]" alt="">
                    </a>
        </li>`
        ]]
        
        


        Should work no issue.

        Hope it helps.
        Tyreal2012, thank you for help! It's work's exacly i need ))

        Solution:
        1. I created new chunk slide_item with code:
        [[If? 
            &subject =`[[+url]]` 
            &operator=`isempty` 
            &then=`
            <li>
                <img src="[[+image]]" alt="" />
            </li>` 
            &else=`
            <li>
                <a href="[[+url]]" title="[[+text]]">
                    <img src="[[+image]]" alt="" />
                </a>
            </li>
        `]]


        2. Then add into my slider chunk:
                <ul class="bjqs">
                [[!getImageList?
                    &tvname=`slider_main`
                    &tpl=`slide_item`
                ]]
        </ul>

        That's all.

          • 30912
          • 463 Posts
          Exactly it - half the time its working out the right combination for IF, there is also ANDIF which is a snippet on the forum for multiple conditions if needed.
            • 48853
            • 12 Posts
            Quote from: Tyreal2012 at Oct 16, 2014, 11:41 AM
            Exactly it - half the time its working out the right combination for IF, there is also ANDIF which is a snippet on the forum for multiple conditions if needed.
            You mean http://forums.modx.com/thread/32601/andif---conditional-snippet-allowing-multiple-and-or-conditions never heard before about this snippet, interesting...

            Thank you again for help! Goodluck to you )))
              • 30912
              • 463 Posts
              Thats the one, another helpful one