path to generated contenful middleman data file

109 views Asked by At

'universal_meganav' is the name of my contentful space. My data folder looks like:

enter image description here

PCWLCTeTCKsaoGGSQOc6i.yaml is generated by the contenful_middleman build command. It contains:

---
:id: PCWLCTeTCKsaoGGSQOc6i
:pageTitle: This is a test title

How do I access this :pageTitle: in my views without relying on the generated file name?

<%= data.universal_meganav.homepage %>

returns

{"PCWLCTeTCKsaoGGSQOc6i"=>{"id"=>"PCWLCTeTCKsaoGGSQOc6i", "pageTitle"=>"This is a test title"}}

I was trying <%= data.universal_meganav.homepage[0] %> but this isn't working. I've seen examples manipulating the data in config.rb in a loop but I get an error of "NoMethodError: undefined method 'universal_meganav' for nil:NilClass" if I try and access data.universal_meganav in config.rb

1

There are 1 answers

4
David Litvak On BEST ANSWER

You can access the content as a list:

<% data.universal_meganav.homepage.each do |_, item| %>
  <h1><%= item.pageTitle %></h1>
  <!-- ... etc ... -->
<% end %>