0

EE v2.4.0 (Updating is not an option at this time)

Hello! The photo gallery that we use still shows up even when no photos are added. Basically what I'm trying to do is get the image gallery to show only if a user uploaded an image. I've done this type of thing before on 2.9.2, but for some reason (I suspect a version issue) it's not working.

Here is the original code:

        <div class="left article_image">
          <ul data-orbit>
          {article_images}
                <li>
                  <img src="{image_matrix_image}" alt="">
                  <div class="caption">
                    <p>{image_matrix_cutline}<em>  ({image_matrix_byline})</em></p>
                  </div>
                </li>
            {/article_images}
          </ul>
       </div>

And here is what I've added:

     <div class="left article_image">
       {if article_images}
          <ul data-orbit>
          {article_images}
                <li>
                  <img src="{image_matrix_image}" alt="">
                  <div class="caption">
                    <p>{image_matrix_cutline}<em>  ({image_matrix_byline})</em></p>
                  </div>
                </li>
            {/article_images}
          </ul>
          {if:else}
          {/if}
       </div>

So you see, what should be an easy task, is just not working. The result is both an empty album not showing and an album with images not showing. How big of a newbie am I and what am I missing? I have tried moving around the ifs and ifelses. I have also tried using '== true'.

Any help is greatly appreciated. Thank you so much!

Here is what it looks like when a user does not add an image in ExpressionEngine and posts the article. The gallery slider still shows up.

Picture of empty image slider above.

2

If I read your code correctly, you use Matrix field to keep images. Try next code for this:

 <div class="left article_image">
   {if article_images:total_rows>0}
      <ul data-orbit>
      {article_images}
            <li>
              <img src="{image_matrix_image}" alt="">
              <div class="caption">
                <p>{image_matrix_cutline}<em>  ({image_matrix_byline})</em></p>
              </div>
            </li>
        {/article_images}
      </ul>
      {if:else}
      {/if}
   </div>
  • Hmm I seem to be getting a parse error when I try this. I've also played around with it some more and all have failed. I've also tried {if article_images:total_rows >= 0} But, this total_rows attribute seems like it's the obvious way to go. Thank you for your help, I'll keep pluggin' away! – compiled Jan 28 '15 at 16:27
  • 1
    try to use it this way {if "{article_images:total_rows}">0} – Max Lazar Jan 28 '15 at 16:29
  • As a string, really? Interesting. I tried this and fortunately no parse error, but still no change. Empty image slider still weirdly shows up. Edit: I didn't mean for this to sound offensive if it did, sorry! haha – compiled Jan 28 '15 at 16:34
  • 1
    for string you can use {if "{article_images:total_rows}" != "0"} but question is - what html code you have now for empty images? Do you have everything what inside <li></li>? – Max Lazar Jan 28 '15 at 17:08
  • 1
    is this site online? send me message to max at eec.ms – Max Lazar Jan 28 '15 at 17:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.