Gem Version Inline docs

Gem | Source | Documentation

Allows adding more view hooks into Redmine's templates


Ensure you have a Gemfile.local file in your Redmine installation. Add to your Gemfile.local:

gem "redmine-more_view_hooks"

And then execute:

$ bundle

Restart the Redmine application


Redmine already includes a concept of "view hooks", but not every place already has such a hook. For example, a hook before the user login status in the top menu is missing.

Let's assume the needed view hook would already exists at the desired position and would be called layout_base_logged_as_before. In this case one can simple write a new view hook listener as natively supported from Redmine:

class Hooks < Redmine::Hook::ViewListener
  # Redmine runs this method whenever a <%= call_hook(:layout_base_logged_as_before) %>
  # is included into the templates.
  # Attention: This view hook doesn't exists in Redmine and must be realized using this gem
  def layout_base_logged_as_before(context)
     :span, "Some additional content"

To bring this to live we need to add this new view hook into Redmine's base layout template. Using this gem you can inject every needed view hooks into every possible template. The needed hook can be achieved using the following statement:

  # first the name of the new view hook
  # now some Deface options to determine the correct position of the hook
  virtual_path:  "layouts/base",
  insert_before: "#top-menu erb[loud]:contains('if User.current.logged?'):contains('content_tag')"

For more information about the Deface options please have a look at their documentation.

The correct place to register new view hooks would be when initializing your Redmine plugin.

Avoiding hook definitions with identical names

Redmine allows multiple hook definitions with identical names across separate hook listeners.

MoreViewHooks.add disallows hook definitions using the same name. So this won't work:

MoreViewHooks.add(:unique_name, ...)

# raises "A view hook 'unique_name' already exists (ArgumentError)"
MoreViewHooks.add(:unique_name, ...)

Note: Defining a hook via MoreViewHooks.add re-using an existing Redmine hook name should work without problems.

Here is an example how to avoid duplicate hook names:

unless Redmine::Hook.hook_listeners(:view_projects_show_left).any?
    virtual_path: "projects/show",
    insert_top:   "div.contextual"

Tested Redmine versions

  • Redmine 1.x
  • Redmine 2.x
  • Redmine 3.0 - 3.2


  1. Fork it ( )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request