We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 42901 ☆ A M B ☆
    • 73 Posts
    Hello everybody,

    I'm trying to find out how to make something conditional. (Let me explain this a little deeper)

    I have a TV setup for inserting up to 5 images for a slideshow.
    However, I would like to have the option of using less than all 5 images if possible.

    Here is my HTML code being used.

    <section class="slideshow">
      <ul class="slides">
        <li><img alt="[[*SlideOneTitle]]" src="[[*SlideOneSrc]]"></li>
        <li><img alt="[[*SlideTwoTitle]]" src="[[*SlideTwoSrc]]"></li>
        <li><img alt="[[*SlideThreeTitle]]" src="[[*SlideThreeSrc]]"></li>
        <li><img alt="[[*SlideFourTitle]]" src="[[*SlideFourSrc]]"></li>
        <li><img alt="[[*SlideFiveTitle]]" src="[[*SlideFiveSrc]]"></li>
      </ul>
    </section>
    


    If I only use 1 image, I will be stuck with 4 blank <li> tags in my page. How can I make it conditional based on the number of src=" " added?

    This is probably something basic but as of right now, I am only about a week into use MODX Revolution. My work-around currently consists of 5 chunks:

    1. [[$Image]] (I use this because obviously, 1 image is not a slideshow)
    2. [[$Gallery2]]
    3. [[$Gallery3]]
    4. [[$Gallery4]]
    5. [[$Gallery5]]

    Each chunk has only the specific HTML code to satisfy the number of uploaded images but that is my rookie way of making this work. A single image wouldn't really need the <ul> and <li> tags.
    It would be nice if there was a way to solve this using a conditional. I'm not a programmer so...

    Of course any help would be greatly appreciated! [ed. note: adagency last edited this post 13 years, 7 months ago.]
      Woodlands Ad Agency
      Our blog should NOT be read by anyone....EVER http://woodlandsadagency.com/blog/
      ...Don't say we didn't warn you.
      • 37523
      • 141 Posts
      You do not need to use conditional code to achieve what you are after. You can use the Gallery package. This can be downloaded through the Package Manager (System -> Package Management then click on the Download Extras button).

      Gallery will allow you to upload the images to the website and then create a conditional chunk to access them which ever way you like.

      Information on the Gallery package can be found at http://rtfm.modx.com/display/ADDON/Gallery. A tutorial on its usage can be found here

      Please note that the above is only 1 approach to the issue. Within Modx there are many ways to do the same thing.
        Glyn Szasz
        Sydney, Australia

        Happy to help (when can) and happy to learn

        If you are a Sydney based MODX developer would love to hear from you. Please contact me.
        • 25803 ☆ A M B ☆
        • 721 Posts
        You should check out MIGX. It allows a single Template Variable to act as a collection of other Template Variables, in effect, creating an array.

        http://modx.com/extras/package/migx
        http://rtfm.modx.com/display/ADDON/MIGX
        https://forums.modx.com/board/?board=271

        We use it constantly for all sorts of things, including galleries.
          • 37523
          • 141 Posts
          @RX2 You have just given me a really good understanding of what to use MIGX for. Thanks. Like I said above there are many ways to do the same thing in MODX.
            Glyn Szasz
            Sydney, Australia

            Happy to help (when can) and happy to learn

            If you are a Sydney based MODX developer would love to hear from you. Please contact me.
            • 42901 ☆ A M B ☆
            • 73 Posts
              Woodlands Ad Agency
              Our blog should NOT be read by anyone....EVER http://woodlandsadagency.com/blog/
              ...Don't say we didn't warn you.
              • 10357
              • 573 Posts
              migx would be my choice, but you can do something like this:

              [[*SlideOneSrc:notempty=`<li><img alt="[[*SlideOneTitle]]" src="[[*SlideOneSrc]]"></li>`]]
              

                • 42901 ☆ A M B ☆
                • 73 Posts
                This is great stuff. Thanks to everybody who has chimed in so far. MIGX seems like the future solution while g5604's tidbit of code is EXACTLY the solution for my immediate needs.

                MODX just keeps exceeding my expectations and this forum's people make it that much better!
                  Woodlands Ad Agency
                  Our blog should NOT be read by anyone....EVER http://woodlandsadagency.com/blog/
                  ...Don't say we didn't warn you.
                  • 25803 ☆ A M B ☆
                  • 721 Posts
                  I'd also look at this article: http://modx.com/blog/2012/09/14/tags-as-the-result-or-how-conditionals-are-like-mosquitoes/

                  Better performance than using the element modifier method in the official docs. As far as I know, this method has not made it into the official documentation.
                    • 42967
                    • 143 Posts
                    I think the most efficient way to do this is:
                    [[*SlideOneSrc:default=`<li><img alt="[[*SlideOneTitle]]" src="[[*SlideOneSrc]]"></li>`]]


                      Eighth day design
                      Design agency with offices in Edinburgh and Brighton
                      • 38723
                      • 165 Posts
                      Unless I've completely misinterpreted what you're asking - you can do something simple like this which will avoid you needing to install extras to do the same thing.

                      :)

                      <section class="slideshow">
                        <ul class="slides">
                          [[*SlideOneSrc:notempty=`<li><img alt="[[*SlideOneTitle]]" src="[[*SlideOneSrc]]"></li>`]]
                          [[*SlideTwoSrc:notempty=`<li><img alt="[[*SlideTwoTitle]]" src="[[*SlideTwoSrc]]"></li>`]]
                          [[*SlideThreeSrc:notempty=`<li><img alt="[[*SlideThreeTitle]]" src="[[*SlideThreeSrc]]"></li>`]]
                          [[*SlideFourSrc:notempty=`<li><img alt="[[*SlideFourTitle]]" src="[[*SlideFourSrc]]"></li>`]]
                          [[*SlideFiveSrc:notempty=`<li><img alt="[[*SlideFiveTitle]]" src="[[*SlideFiveSrc]]"></li>`]]
                        </ul>
                      </section>