2

I have an image that is an optional channel field, and I've got it hard coded into the template. If someone doesn't attach an image, there is an empty image box on the page for that entry. How can I tell EE to check for an image, and if its not there, just load the rest of the page normally?

| improve this question | | | | |
9

I think this should work:

In this example I use three custom fields: article_image, image_description and class.

{if article_image != ""}
   <img src="{article_image}" alt="{image_description}" title="{image_description}" class="{class}" />
{/if} 

You can also use the shorthand version of the above code like so "{if custom_field}content here{/if}". This shortens up the code a bit.

| improve this answer | | | | |
  • There is a {} button in the editor, or simply indent it by four spaces (we use markdown formatting) – Adrian Macneil Jan 6 '13 at 0:15

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.