Helmut Granda
Helmut Granda

Reputation: 4685

Jekyll access data files from inside a plugin

How do we access information inside the "_data" folder from inside a "_plugin"?

for example I have _data/items.yml

item
  data1: info
  data2: moreinfo

inside my plugin in the render method I want to be able to

def render(context)
  <<--MARKUP.strip
  <p>#{site.data.items.data1}</p>
  MARKUP
end

Any ideas? I have been able to get site.data.items but I have not been able to access the children elements (data1, data2)

Upvotes: 1

Views: 527

Answers (2)

Helmut Granda
Helmut Granda

Reputation: 4685

I had to use a combination of two answers:

How to pass items to my plugin: Custom Liquid tag with two parameters

parse and access json data: How to convert ruby formatted json string to json hash in ruby?

Upvotes: 0

ashmaroli
ashmaroli

Reputation: 5444

Your data file _data/items.yml has an item key as well.

item
  data1: info
  data2: moreinfo

So data1 is actually accessed by site.data.items.item.data1 and
data2 by site.data.items.item.data2

Upvotes: 2

Related Questions