Skip to content

Instantly share code, notes, and snippets.

@jipiboily
Created April 8, 2012 18:12
Show Gist options
  • Save jipiboily/2338880 to your computer and use it in GitHub Desktop.
Save jipiboily/2338880 to your computer and use it in GitHub Desktop.
How to setup a Refinery custom content type and view (aka "page template")
<!-- path: app/views/refinery/admin/pages/_actions.html.erb -->
<!--
You could override this view, if you want to add links to each page type via the admin UI. If you don't you'll have to add a param the the URL.
WARNING: You most probably want to do it cleaner than that and find a way to hook to this view instead of overriding it if at all possible.
-->
<ul>
<li>
<%= render '/refinery/admin/search', :url => refinery.admin_pages_path %>
</li>
<li>
<%= link_to t('.create_new_page') + " (standard)", refinery.new_admin_page_path,
:class => "add_icon" %>
</li>
<% Refinery::Pages.types.each do |type| %>
<li>
<%= link_to t('.create_new_page') + " (#{type.name.to_s})", refinery.new_admin_page_path + "?view_template=" + type.name.to_s, :class => "add_icon" %>
</li>
<% end %>
<% if @pages.many? and !searching? %>
<li>
<%= link_to t('.reorder_pages'), refinery.admin_pages_path,
:id => "reorder_action",
:class => "reorder_icon" %>
<%= link_to t('.reorder_pages_done'), refinery.admin_pages_path,
:id => "reorder_action_done",
:style => "display: none;",
:class => "reorder_icon" %>
</li>
<% end %>
</ul>
<!--
path: app/views/refinery/pages/my_new_view.html.erb
usage: this is a view_template you can choose in the advanced part of a page creation, see the initializer to enable it.
-->
<%= raw @page.content_for(:intro) %>
<%= raw @page.content_for(:body) %>
<%= raw @page.content_for(:right) %>
<%= raw @page.content_for(:footer) %>
<%= raw @page.content_for(:related) %>
#config/initializers/refinery/pages.rb
Refinery::Pages.configure do |config|
# ...
# this is how to define a new type of page with custom parts.
config.types.register :my_content_type do |content_type|
content_type.parts = %w[intro body right footer related]
end
# this is the list of views that you can choose from the admin UI, see the added custom view template.
config.view_template_whitelist = ["home", "show", "my_new_view"]
# this will enable the use of custom view templates.
config.use_view_templates = true
# ...
end
@jipiboily
Copy link
Author

@Soldo: please create a gist with ALL the content of your routes.rb, PagesController override, pages.rb initializer, your new view (bidon or my_new_view, whichever is current). Currently, I don't have enough material to give you an explanation. I would need all your code concerning the problem. Can you also tell me what are the exact specs of what your are trying to do.

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment