How to access specific row from CSV with Jekyll? -


i using jekyll [2.5.3] build prototype , need access specific rows file in _data in layouts.

in file _data/badges.csv have:

name, image_url heat, http://pathtoimage.com/image-1.png water, http://pathtoimage.com/image-2.png zoning, http://pathtoimage.com/image-3.png ... 

in _layout/page.html trying access zoning row badges.csv passing value site.data so:

{% assign badge = site.data.badges.name["zoning"] %} {{ badge.image_url }} 

eventually make ["zoning"] page variable load specific badges based on page.

i've tried [zoning], ['zoning'], ["zoning"]. none of these output data , not throw error during jekyll build.

how can access specific row csv?

i believe csv files treated arrays instead of maps. if want find specific entry in csv this:

{% badge in site.data.badges %}   {% if badge.name == "zoning" %}     {{ badge.image_url }}   {% endif %} {% endfor %} 

you move _includes , pass argument reuse functionality:

_includes/badge-url.html

{% badge in site.data.badges %}   {% if badge.name == include.name %}     {{ badge.image_url }}   {% endif %} {% endfor %} 

including zoning

{% include badge-url.html name="zoning" %} 

Comments

Popular posts from this blog

javascript - Chart.js (Radar Chart) different scaleLineColor for each scaleLine -

apache - Error with PHP mail(): Multiple or malformed newlines found in additional_header -

java - Android – MapFragment overlay button shadow, just like MyLocation button -