-
Notifications
You must be signed in to change notification settings - Fork 1
Page specific metadata
Dylan Fisher edited this page Nov 5, 2018
·
2 revisions
You may encounter situations where you want to add content to a particular page (or other model) in a way that doesn't involve changing the database structure or creating new block kinds. One way to do this is storing the information in the record's blockable_metadata
column. The following examples show how to add a special description and video URL field to a page named "Home".
# page_decorator.rb
Page.class_eval do
store_accessor :blockable_metadata, :home_page_description, :home_page_video_url
end
<%# admin/pages/_additional_inputs.html.erb %>
<% if @page.try(:slug).present? %>
<% begin %>
<%= render "#{@page.slug}_page_settings", f: f %>
<% rescue ActionView::MissingTemplate => e %>
<% logger.info { "[Forest][Info] No additional page settings template found for #{@page.slug}" } %>
<% end %>
<% end %>
<%# admin/pages/_home_page_settings.html.erb %>
<div class="panel panel-default" data-collapse-parent>
<div class="panel-heading">
<h3 class="panel-title">
Home Page Settings
<button type="button" class="btn btn-default btn-xs pull-right" data-collapse-trigger>
<div class="collapsable-icon glyphicon glyphicon-chevron-up"></div>
</button>
</h3>
</div>
<div class="panel-body" data-collapse-body>
<div class="form-inputs">
<div class="row">
<div class="col-sm-12">
<%= f.input :home_page_video_url %>
<%= f.input :home_page_description %>
<%= f.button :submit, class: 'btn-success' %>
</div>
</div>
</div>
</div>
</div>