Skip to content

Instantly share code, notes, and snippets.

@Soldo
Forked from jipiboily/_actions.html.erb
Created April 9, 2012 22:44
Show Gist options
  • Save Soldo/2347127 to your computer and use it in GitHub Desktop.
Save Soldo/2347127 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"]
# ...
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment