Question

I have a JSON data file in my Middleman project that has an object with info about 5 sections of a a site where we are building prototypes for a new project. Here is part of that file:

"industries": {
  "Insulation": {
    "url": "insulation",
    "color": "#B48126"
  },
  "Roofing": {
    "url": "roofing",
    "color": "#52bd4a"
  }, ...

I'd like to pull attributes from that object based on the current page.

For instance, if I'm on page in the Insulation section, I'd like grab the highlight color for insulation from that file and use it as part of the prototype, so that we can try different colors for the client.

At the top of each .erb template, I could very easily put this page data variable to denote the industry:

;;;
"product": "Commerical Insulation",
"division": "insulation"
;;;

and then further down the template, use things like this:

  <img  class="img-responsive center-block" 
        src="<%= lorem.image('1140x100', 
              :text => current_page.data.product + ' image', 
              :color => data.lists.industries.{current_page.data.division}.color) %>" />

I know {current_page.data.division} is not right (throws a syntax error, unexpected tLBRACE).

I'm new to Ruby and ERB, so if there is a better way to approach this, I'm open to suggestions.

Was it helpful?

Solution

Did you try data.lists.industries[current_page.data.division].color?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top