4

I have a grid field set up for social links. The first column selects the network, the second field a link. I'd like to have a conditional working so it tests against the content and adds corresponding classes:

{exp:channel:entries channel="social" disable="category_fields|member_data|pagination" limit="1"}{social_links}
<li class="{if {social_links:network}=="Google"}google{/if}">Our <a href="{social_links:network_url}">{social_links:network}</a></li>
<li class="{if {social_links:network}=="Twitter"}google{/if}">Follow us on <a href="{social_links:network_url}">{social_links:network}</a></li>
<li class="{if {social_links:network}=="Facebook"}google{/if}">Join us on <a href="{social_links:network_url}">{social_links:network}</a></li>
{/social_links}{/exp:channel:entries}

I'd also like to be able to test if a grid field is empty like:

{if social_links!=""}Do something {if:else} or do this{/if}

Any ideas?

3
  • I've also tried: {if social_links:network=="Google"}google{/if} - but this had no effect either.
    – liamcrean
    Sep 20, 2013 at 10:32
  • Have you tried class="{if '{social_links:network}' == 'Google'}google{/if}" Sep 20, 2013 at 12:02
  • @JeanSt-Amand you ought to make that a statement and put it as an answer. I think it'll solve the problem. Point out the importance of the single and double quotes. :) Sep 20, 2013 at 12:32

1 Answer 1

4

I'd recommend trying class="{if '{social_links:network}' == 'Google'}google{/if}"

Whatever you use for the conditional, if you match up the quotes usage (double versus single), it makes a big difference.

1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.