title: Conditionally add data-attributes in Jekyll
body: <p>My basic YAML Front Matter for blog posts looks as:</p>
  
  <pre><code>   layout: post
     title:  'Crepes'
     permalink: /crepes/
     src: '/assets/images/crepes.jpg' 
     date:   2018-05-24 21:41:00
     origin: http//...
     ingredients: 
      - ingredient1: amount
      - ingredient2: amount 
  </code></pre>
  
  <p>Here is my index.html to display entries:</p>
  
  <pre><code>&lt;ul&gt;
  {% for post in site.posts %}
  
  &lt;li data-title='{{ post.title }}' data-origin="{{ post.origin }}"
      data-src="{{ post.src | prepend: relative_url}}" 
      data-content='{ "ingredients": {{ post.ingredients | jsonify }} }'&gt;
  
      &lt;a href="{{ site.baseurl }}{{ post.url }}"&gt;
          &lt;img src="{{ post.src | prepend: relative_url }}" alt={{ post.title }}/&gt;
      &lt;/a&gt;
  
  &lt;/li&gt;
  {% endfor %}
  &lt;/ul&gt;
  </code></pre>
  
  <p><strong>The problem is:</strong>
  Some posts are supposed to have no origin value, like <code>origin:</code>. And I am looking for a way to add data-origin attribute only if it's value specified in YAML Front Matter. </p>
  
  <p>Liquid give following option:</p>
  
  <pre><code>{% if condition %}
      &lt;li&gt;....&lt;/li&gt;
  {% endif %}
  </code></pre>
  
  <p>Is there any way to use it inside of html tag? In my case I expect something like this:</p>
  
  <pre><code> {% for post in site.posts %}
  
   &lt;li  
       {% if post.origin has value %}
           data-origin="{{ post.origin }}"
       {% endif %}"&gt;      
  &lt;/li&gt;
  {% endfor %}
  </code></pre>