1

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)

HSchmale
  • 1,838
  • 2
  • 21
  • 48
Helmut Granda
  • 4,565
  • 7
  • 35
  • 51

2 Answers2

2

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

ashmaroli
  • 5,209
  • 2
  • 14
  • 25
0

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?

Community
  • 1
  • 1
Helmut Granda
  • 4,565
  • 7
  • 35
  • 51