0

Cannot seem to work this out!

I have two fields, one is an image {e_image} and the other is plain text {e_map}. Both of these display a div in the exact same spot.

What I want, is if an image is uploaded to the {e_image} field, AND text is added to the {e_map} field, then ONLY the image will appear (it is prioritised over the map {e_map) field). Both cannot appear on the page.

So something like below:

{if e_image}
 <div>{e_image}</div>
{if:elseif e_map}
 <div>{e_map}</div>
{/if}

And obviously if both fields are left empty, nothing appears.

Any help is much appreciated.

  • Your demo code is already perfect for what you want. – Mufi - Amici Infotech Apr 14 '17 at 5:46
  • Thanks, was however having an issue which I have noted below. May be a bug. – ZEDG Apr 14 '17 at 6:11
0

Try

{if e_image}
 <div>{e_image}</div>
{if:elseif e_map && ! e_image}
 <div>{e_map}</div>
{/if}
| improve this answer | |
  • Thanks this works... however it appears to have the same issue as with the example code i pasted. Both fields have content, but to test I remove the image from the field - which should then only display the map. However nothing then appears, as if the map field has no content. I re-save the entry (making no change) and then the map appears. Strange, but maybe some kind of bug. I guess I can live with it though as the possibility of the image having to be removed would be minimal. – ZEDG Apr 14 '17 at 6:08
  • Just a minor thing but might fix the problem - you don't need the && ! e_image in the second conditional as is already covered by the {if:elseif}. Removing the redundant second test for e_image might help with the logic bug you are seeing. – JCOGS Design Apr 14 '17 at 17:40

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.