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,541
  • 2
  • 17
  • 40
Helmut Granda
  • 4,056
  • 4
  • 28
  • 44

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
  • 4,499
  • 2
  • 10
  • 24
  • 1
    Thanks for the comment and although site.data.items.item.data1 and so forth work great I am looking to how to access the data from within a plugin. – Helmut Granda Apr 08 '17 at 04:38
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,056
  • 4
  • 28
  • 44