My basic YAML Front Matter for blog posts looks as:
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
Here is my index.html to display entries:
<ul>
{% for post in site.posts %}
<li data-title='{{ post.title }}' data-origin="{{ post.origin }}"
data-src="{{ post.src | prepend: relative_url}}"
data-content='{ "ingredients": {{ post.ingredients | jsonify }} }'>
<a href="{{ site.baseurl }}{{ post.url }}">
<img src="{{ post.src | prepend: relative_url }}" alt={{ post.title }}/>
</a>
</li>
{% endfor %}
</ul>
The problem is:
Some posts are supposed to have no origin value, like origin:
. And I am looking for a way to add data-origin attribute only if it's value specified in YAML Front Matter.
Liquid give following option:
{% if condition %}
<li>....</li>
{% endif %}
Is there any way to use it inside of html tag? In my case I expect something like this:
{% for post in site.posts %}
<li
{% if post.origin has value %}
data-origin="{{ post.origin }}"
{% endif %}">
</li>
{% endfor %}