Using a 'Where' filter in Jekyll to only return items that are not blank -
i have csv data file contains list of projects. assign variables filtered segments of data - loop through them.
here have tried filter projects show projects have been assigned value in global_priority
field. if project has no value not in list.
i have tried using where_exp
, returns everything. best way approach this? possible achieve without using if
statement?
projects.csv
name,global_priority,region,region_priority project a,1,global, project b,,spain,1 project c,2,uk,1
the loop
{% assign projects = site.data.projects %} {% assign global_p = projects | where_exp: "item.global_priority", "item.global_priority != blank" %} {% p in global_p %} <ul> <li>{{ p.global_priority }}</li> <li>{{ p.region }}</li> <li>{{ p.name }}</li> </ul> {% endfor %}
there small mistake in way access where_exp
item, should refer name use in comparation: where_exp: "item"
then:
{% assign global_p = site.data.projects | where_exp: "item", "item.global_priority" %} {% p in global_p %} <ul> <li>{{ p.global_priority }}</li> <li>{{ p.region }}</li> <li>{{ p.name }}</li> </ul> {% endfor %}
outputs:
<ul> <li>1</li> <li>global</li> <li>project a</li> </ul> <ul> <li>2</li> <li>uk</li> <li>project c</li> </ul>
Comments
Post a Comment