[ask] passing variable to view hook?
Added by rangga rahadian over 10 years ago
how to passing a variable from class hook to hook html?
i tried write simple code as below, but the variable didnt printed.
hook file :
module Hooks
class showUserHook < Redmine::Hook::ViewListener
@var = 1 + 2
render_on :view_account_left_bottom, :partial => "account/showhook"
end
end
and views/account/showhook.html.erb file:
output :
expected output :
thanks for your reply
Replies (1)
RE: [ask] passing variable to view hook?
-
Added by Akiko Takano over 10 years ago
Hi. I think you can pass variables into partials as local variables.
How about?
module Hooks
class showUserHook < Redmine::Hook::ViewListener
var = 1 + 2
render_on :view_account_left_bottom, partial: "account/showhook”, locals: { var: var }
end
end
Such as account/_showhook.html.erb
Note: Instance variable like @user is passed from controller.
I hope this can help you.