Low Variables & Conditionals: if variable has a value, display content
Hi Low,
I couldn't find an answer to this, so I apologize if this has already been solved here on the forums or in the docs.
I'm using Low Variables to display "global" information on my site in the footer. For instance: global contact information (address, phone, fax), and social media links (twitter, fb, linkedin). I only want to display the variable value(s) and their surrounding markup if the variable actually has a value.
Is there a preferred way to do this?
Currently, this is how I'm doing it in my template, and this works:
{exp:low_variables:pair var="low_cli_social_twitter"}
{if low_cli_social_twitter}
<li class="social-media-twitter">
<a href="{low_cli_social_twitter}" rel="me">
<span class="icon-twitter"></span>
<span class="screen-reader-text">Follow COMPANY on Twitter</span>
</a>
</li>
{/if}
{/exp:low_variables:pair}
But, that syntax can get pretty tough to look at, especially when doing a lot of conditionals for the microformats markup on the address. Is there a "simpler" syntax that I'm able to take advantage of?
Thanks!
Replies
Low 13 Dec 2013 21:50
If you enable early parsing for a variable, you can use the variable syntax and use it in a conditional:
ctrlaltdel 16 Dec 2013 19:41
Thank you, Low. That worked! I appreciate the help.