vale
vale

Reputation: 1426

Check for empty fields in Jekyll data files

My data file is as follows:

- title: Title  
  description: Lorem Ipsum .....  
  link: http://link.com  
  social: facebook  
  sociallink: http://facebook.com  

- title: Title2 
  description: Lorem Ipsum .....  
  link: http://link.com  

The index.md page is as follows:

{% for member in site.data.info %}

##[{{ member.name }}]({{ member.link }})   

{{ member.description }}   

[{{ member.social }}]({{ socialLink }})

{% endfor %}

Some items don't have a social field or a socialLink field. I'd like not to print them out as []().

Is there some kind of tag to check if a field exists, like {% if member has field %} // {% end if %}?

Upvotes: 2

Views: 1031

Answers (1)

approxiblue
approxiblue

Reputation: 7122

There's no special operator, the if tag can check if (ha) a variable exists:

{% if member.social %}
  {{ member.social }}
{% endif %}

Upvotes: 3

Related Questions