I want to create a helper for use in sinatra's Template.

Asked 2 years ago, Updated 2 years ago, 101 views

Image

#helper
view_helper do
    hoge(fuga)do
        US>"#{fuga}"
    end
end

#view
hoge('Bob') #This is Bob

I would like to use it like this, but what is the best way? I don't know how to make it in the first place.

Please let me know

ruby sinatra

2022-09-30 20:29

1 Answers

Sinatra FAQ seems to have a description

Sinatra: Frequently Asked Questions - How do I access helpers from within my views?

In hello.rb:

helpers do
  defem(text)
    "<em>#{text}</em>"
  end
end

get'/hello'do
  @subject='World'
  haml —Hello
end

Views/hello.haml:

%p="Hello"+em(@subject)


2022-09-30 20:29

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.