Open link in a new tab

Content

Expand project menu

[Plugin Development] How to use a helper from hook view template?

Hi Guys,

I have an issue when porting ChilliProject TimeTracker plugin (https://github.com/magiclabs/ChiliProject-TimeTracker) to OP.

I have used the openproject-plugin generator and took inspiration from the openproject-backlogs plugin, but my hooks templates are not able to see helpers (I have the classic rails engine app structure).

How is possible to use helper from the hook template?

AFAIK in the case of hook none from controllers of the plugin are used, therefore I need to include the helper somehow differently. How?

Thanks,

Kind regards
Tomáš

Message actions

Hello Tomáš,

have you had a look into code>hooks.rb ? As far as I know you simply include the helpers you need (like WorkPackageHelper in hooks.rb).

Have you published your code already? If yes, we may have a look into it?

Kind regards,
Hagen

Message actions

Hello Hagen,

I have not published it yet, because I would like to publish the working version of it.

Yes, I have looked at hooks.rb and done it in the same way, my hooks.rb in the TimeTracker plugin looks like this:

# This class hooks into Redmine's View Listeners in order to add content to the page
module OpenProject::TimeTracker::Hooks
    class LayoutHook < Redmine::Hook::ViewListener
        include ApplicationHelper
        include TimeTrackersHelper

        render_on :view_layouts_base_body_bottom, :partial => 'time_trackers/update_menu'
        render_on :view_issues_context_menu_start, :partial => 'time_trackers/update_context'
        render_on :view_layouts_base_sidebar, :partial => 'time_trackers/embed_menu'
    end
end

But it does not work :-(. Methods from my helpers are not defined in my hook templates…

An idea?

Message actions

Hello Tomáš,

so, now I am little bit confused. :-)

The ApplicationHelper in line 4, is it your own or do you try to include core’s ApplicationHelper?. If you try the latter, you may remove the include because the code>ViewListener already includes it.

At the moment I just think that the modules/namespaces are mixed up. But that is just a guess. ;-)

Kind regards,
Hagen