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>
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With