Adding custom content¶
This is how the content of the Extended Profile plugin is added to the author box...
To support customization the Author Box provides the:view_sidebar_author_box_bottom
hook, which gets executed with the following data in the context
:
:user
-- the user object, for which the author box is rendered;:count
-- the total number of users, for whom author boxes are rendered (may be used to determine the rendered size of custom data in the box, as multiple author boxes are slightly smaller).
:project
-- the project object, for which the author box gets rendered;:request
-- the request object containing all the details about the request.
The hook can be used in the following way:
class ExtendedFieldsHook < Redmine::Hook::ViewListener
render_on :view_sidebar_author_box_bottom, :partial => 'author_box/custom_data'
end
Here author_box/custom_data
(use your own directory and file names) refers to the partial view file author_box/_custom_data.html.erb
, the content of which can look like:
In this sample code I display the progress bar showing the percentage of projects, the user participates in (is member of).
<% all_projects = Project.count(:conditions => Project.visible_condition(User.current)) %>
<% user_projects = user.memberships.all(:conditions => Project.visible_condition(User.current)).count %>
<%= progress_bar(user_projects * 100 / all_projects, :width => '120px', :legend => "#{user_projects} of #{all_projects} projects") %>
This renders the author, box which looks like:
See also: