3

This config.rb works:

helpers do
    def link_to_nothing(text)
        link_to(text, "#")
    end
end

With template index.html.erb:

<%= link_to_nothing "Test link" %>


But when I try to add a method to the Middleman::Sitemap::Resource class in this config.rb:

helpers do
    class Middleman::Sitemap::Resource
        def link(text)
            link_to(text, path)
        end
    end
end

With template index.html.erb:

<%= current_page.link "This page" %>

The following error comes up when loading the page:

NoMethodError at /index.html

undefined method `link_to' for #<Middleman::Sitemap::Resource:0x3139848>

Spencer
  • 1,161
  • 12
  • 19

1 Answers1

2

I've found that link_to is an instance method of class Middleman::Application, which I can access through the app variable:

helpers do
    class Middleman::Sitemap::Resource
       def link(text)
            app.link_to(text, path)
        end
    end
end
Spencer
  • 1,161
  • 12
  • 19