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.

How to check if a Custom Channel Field contains something with fallback otherwise

August 30, 2012 2:45pm

Subscribe [3]
  • #1 / Aug 30, 2012 2:45pm

    Ian Young

    200 posts

    This is a fairly simple one but I just need to confirmation on how to check if a custom channel field contains something and if not then provide a fallback like this:

    {if food_product_image}
    
        {food_product_image}
    
    {if:else}
        /assets/images/no-image.png
    {/if}

    So if {food_product_image} has been uploaded then display that. If not then display a fallback image. The above doesn’t seem to be working an neither do the comparison operators I’ve tried like == true or ==false or != true etc.

     

  • #2 / Aug 31, 2012 7:11am

    Boyink!

    5011 posts

    This is a fairly simple one but I just need to confirmation on how to check if a custom channel field contains something and if not then provide a fallback like this:

    {if food_product_image}
    
        {food_product_image}
    
    {if:else}
        /assets/images/no-image.png
    {/if}

    So if {food_product_image} has been uploaded then display that. If not then display a fallback image. The above doesn’t seem to be working an neither do the comparison operators I’ve tried like == true or ==false or != true etc.

     

    I would just use two simple conditionals:

    {if food_product_image !=""}
    
        {food_product_image}
    {/if}
    
    {if food_product_image ==""}
     /assets/images/no-image.png
    {/if}

     

  • #3 / Aug 31, 2012 1:42pm

    Shane Eckert

    7174 posts

    Hey Slippy,

    Thank you for posting your question here on the ExpressionEngine forums.

    What do you think of Mike’s example?

    Cheers,

  • #4 / Aug 31, 2012 2:20pm

    Ian Young

    200 posts

    That helps confirm things. Thanks guys.

  • #5 / Sep 04, 2012 1:49pm

    Dan Decker

    7338 posts

    Hi Slippy,

    Good to see that Mike and Shane were able to help.

    If you need anything else, please let us know!

    Cheers,

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

ExpressionEngine News!

#eecms, #events, #releases