ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Showing backup images when none are available for a given channel entry

June 06, 2011 5:12pm

Subscribe [5]
  • #1 / Jun 06, 2011 5:12pm

    greebo

    4 posts

    Hello, long time noobie, first time poster,

    I am trying to create a conditional statement based on the following code:

    {exp:channel:entries channel="galleries" url_title="{embed:product_id}"}
    <div class="products_view_image">
        {gallery}
        <a href="http://{path=%27galleries/view/{url_title}/{row_id}}" rel="cb" title="{image_title}">_        {exp:ed_imageresizer image="{image}" maxWidth="100" maxHeight="100" alt="{image_title}"}_    </a>
        {/gallery}
    </div>
    {/exp:channel:entries}

    I would like to display a default image in case there are not any specified for the given product id. It’s probably a simple answer, but struggling to find anything in the forum or documentation.

    Many thanks.

  • #2 / Jun 06, 2011 6:06pm

    atle

    29 posts

    Sorry, wrong thread for me…

  • #3 / Jun 06, 2011 6:35pm

    Matt:P

    277 posts

    Hi Greebo

    You can use the {if no_results} tag to render something else if no entries are present for a given entries tag.
    See here: http://ellislab.com/expressionengine/user-guide/modules/channel/conditional_variables.html#cond_if_no_results

    or, another approach is to check to see if a specific Field within an Entry has been used:

    {if gallery != ""}
    <a href="http://{path=%27galleries/view/{url_title}/{row_id}}" rel="cb" title="{image_title}">_        {exp:ed_imageresizer image="{image}" maxWidth="100" maxHeight="100" alt="{image_title}"}_</a>
    {/if}

    ...at the top of this page of the documentation…

  • #4 / Jun 07, 2011 5:07am

    John Henry Donovan

    12339 posts

    Hi greebo,

    Welcome to forums 😊

    To further expand on Matt’s example

    {exp:channel:entries channel="galleries" url_title="{embed:product_id}"}
    <div class="products_view_image">
    {if gallery != ""}
    {gallery}
        <a href="http://{path=%27galleries/view/{url_title}/{row_id}}" rel="cb" title="{image_title}">_        {exp:ed_imageresizer image="{image}" maxWidth="100" maxHeight="100" alt="{image_title}"}_    </a>
        {/gallery}
    {if:else}
    /images/default-image.jpg
    {/if}  
        
    </div>
    {/exp:channel:entries}

    Let us know if that helps

  • #5 / Jun 08, 2011 3:54pm

    greebo

    4 posts

    Thanks guys, yep - that helped a lot. Just what I needed!

  • #6 / Jun 08, 2011 5:09pm

    Brandon Jones

    5500 posts

    Awesome, and thanks as well Matt. Glad that helped!

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases