Plugin development: rendering partial inside hook. Where to place partial?
Added by Sebastian Haag over 14 years ago
Hello,
I try to write a plugin which shall include a stylesheet file using a hook. The hook is located in the base layout file and is called view_layouts_base_html_head (app/views/layouts/base.rhtml)
So far my plugin has the following structure (excerpt):
│ init.rb ├───app │ └───views │ └───issues │ _demoPluginIncludeStylesheet.erb ├───assets │ └───stylesheets │ demoPlugin.css ├───lib │ │ demoPluginHooks.rb │ │ │ └───tasks
My hook looks like that:
class DemoPluginHooks < Redmine::Hook::ViewListener render_on :view_layouts_base_html_head, :partial => 'demoPluginIncludeStylesheet' end
So, if the hook is called, _demoPluginIncludeStylesheet.erb should get rendered. This file is located in app/views/issues/, so everything works fine, if the issues page gets called. But if I try to open another page, it says something like "Missing template projects/_demoPluginIncludeStylesheet.erb in view path ..." and thats true, because the file isn`t there...
Where do I have to put the file and what path do I have to specify when calling render_on?
In the plugin tutorial (http://www.redmine.org/wiki/redmine/HowTo_Use_Hooks) it says
10 render_on :view_issues_form_details_bottom, 11 :partial => 'hooks/my_plugin/view_issues_form_details_bottom'
But then I would have to create a folder app/views/hooks/ and have to copy parts of my plugin code to that place and I don´t want to do that... or did I miss something?
I attached the plugin if you want to try. To see the working part of the plugin you have to open something like http://localhost:3000/projects/prj01/issues
Thanks!
Sebastian
Replies (3)
RE: Plugin development: rendering partial inside hook. Where to place partial? - Added by Felix Schäfer over 14 years ago
I haven't read the whole thing, and I'm not quite sure what you are trying to do (seems overly complicated for what I think it does), but the most knowledgeable person for plugins is Eric Davis (edavis10), you can find him on #redmine on freenode.
RE: Plugin development: rendering partial inside hook. Where to place partial? - Added by Timothy High over 14 years ago
You shouldn't have to move anything. What's missing is just the name of the subdirectory under /app/views. Try:
class DemoPluginHooks < Redmine::Hook::ViewListener render_on :view_layouts_base_html_head, :partial => 'issues/demoPluginIncludeStylesheet' end
RE: Plugin development: rendering partial inside hook. Where to place partial? - Added by Sebastian Haag over 14 years ago
now I understand... I just have to create a view folder in my plugin containing the partials and pass this folder and the name of the partial to render_on. I guess thats rails magic ;-)
Felix Schäfer I admit it´s a complicated way to just include a stylesheet. But I didn´t find any better. In some plugins the file layouts/base.rhtml is replaced by the plugin just to include a stylesheet. I don´t want to do that because then I get into trouble if this file changes in the main app or another plugin replaces it too. On the other side now I know how to place view code in layouts/base.rhtml ;-)
Thanks a lot!
Solution:
│ init.rb ├───app │ └───views │ └───abc │ _demoPluginIncludeStylesheet.erb ├───assets │ └───stylesheets │ demoPlugin.css ├───lib │ │ demoPluginHooks.rb │ │ │ └───tasks
class DemoPluginHooks < Redmine::Hook::ViewListener render_on :view_layouts_base_html_head, :partial => 'abc/demoPluginIncludeStylesheet' end