0

More questions I'm afraid!

Hopefully this will be an easy one.

I have a variety of customs fields, not all required. I want to show a block of code, based on whether or not that field has any information in it.

Now if i wanted to just show the field, I can just include it in my template, and if theres no information, it wont show. Fine.

However I want to do something like:

{if custom_field has a value}
<div>
  <p>blah blah {custom_field} blah blah</p>
</div
{/if}

Hope that makes sense!

EDIT: Sorry, still not quite sure. As an example, lets say I have a custom field called "twitter_handle" and that users can input their twitter usernames into it. They don't have to, so it could be left blank, or they could fill it in but I'd have no way of knowing what the value would be.

If I then wanted to show it in my template like so...

{if twitter_handle}
<div class="add me">
  <a href="http://twitter.com/{twitter_handle}">Add me on Twitter</a>
</div
{/if}

Is that right? So i would only get the code wrapped within the if's, provided twitter_username has a value?

4

Yep, very simple. Just do this:

{if custom_field}
 ... field has any value ...
{/if}

If you want to test if the field has a certain value, you can do:

{if custom_field == "foobar"}
 show contents
{/if}
| improve this answer | |
  • Thanks, I've edited my question, as still slightly unsure. – shorn Feb 1 '13 at 3:58
  • Yup, your updated code in your question is correct, as Siebird's answer indicates. – Derek Hogue Feb 1 '13 at 4:03
  • Great stuff, just had a chance to try it and all good! – shorn Feb 1 '13 at 4:04

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.