Proxy Variables (sort of) break on build

I’m having some trouble passing JSON data into a proxy page via a local variable. My build works, but still throws an error:

I’ve got a data file, data/designs.json that is a nested JSON file that looks like this:

{
    "designs": [
        {
            "name": "Name",
            "slug": "slug",
        }
}

I’m generating proxy pages for each of the entries in my designs.json file above. In my config.rb I’ve got:

data.designs.designs.each do |design|
  proxy "/design/#{design['slug']}.html", '/design/template.html', :layout => false, :locals => { :title => design }
end

Where I’m trying to use the local variable title to contain a single entry from my JSON file. In the /design/template.html.erb file referenced above, I try to call that title variable a few times:

image_path = "/source/images/design/#{title['slug']}.jpg"
image_url = "images/design/#{title['slug']}.jpg"

When I run middleman build, it actually builds everything correctly. However, it always tells me it’s throwing an error:

undefined local variable or method `title' for #<Middleman::Application:0x2167500520>

Normally, I’m just ignoring the error since all my pages still build properly, however I’d like to use Middleman-deploy to push up my changes, and it doesn’t work while there is an error.

Any ideas on what might be going wrong here?

I’m not sure why that wouldn’t work - you should file a bug with an example repository that shows off the bug in as little code as possible.

But you could also try just putting slug and name into two different locals:

proxy "/design/#{design['slug']}.html", '/design/template.html', :layout => false, :locals => { :slug => design['slug'], :name => design['name'] }

Finally found a fix to this - looks like I needed to add the :ignore => true flag to my config.rb file.

1 Like

I was confused but after figuring it out here’s a clear example for anyone coming from google and new to middleman, this shows an exmaple of using ignore: true:

:layout =&gt; false, :locals =&gt; { :slug =&gt; design['slug'], :name =&gt; design['name'] }, :ignore =&gt; true

I was also unable to pass down data as the OP mentioned but I resolved it by using bhollis’ suggestion.