-
Notifications
You must be signed in to change notification settings - Fork 2
Creating Templates
Spud CMS Templates take advantage of Rails layout architecture. Without adding extra overhead, almost any rails layout can be used as a spud page template. By default, the default layout is 'application'. This can be changed by modifying the default_page_layout configuration option:
Spud::Cms.configure do |config|
config.default_page_layout = 'my_layout'
end
By default, you will be able to edit the "Body" content of a layout which can simply be rendered in your layout using <%=yield%>
. However, in most sites it is necessary to have multiple sections of a page defined as separately editable areas. To do this we use erb comments to define a 'manifest' similar to how Rail's Asset Pipeline manifest works. Example:
<%
#template_name: 2 Columns
#html: Left
#html: Right
%>
...
Putting this structure at the top of your html.erb file, will inform Spud as to what content sections are available, as well as what to name this template for the user inside the admin panel. In the case of the example above, these content sections are called "Left", and "Right" respectively. This means that they can be rendered within the layout by using <%=yield :left%>
, and <%=yield :right%>
. The names of the content sections are rendered using content_for blocks and their names are converted to an underscored lowercase symbol.
Spud CMS automatically generates the meta tags necessary for your <head>
tags. It is recommended that you add the following line the the bottom of your <head>
tag:
<%=yield :head%>
Sometimes it may be necessary to directly access the page object in your layouts. An example would be to render the page title attribute. Example:
<head>
<title><%=@page.name if !@page.blank?%> | <%=Spud::Core.site_name%></title>
</head>
Multi-site mode is still fairly new, but there are some slight differences in what needs defined on your template for them to work. Templates need to be isolated to the particular site you are using it for. To do this you need to add the #sites:
directive to your template manifest. Example:
<%
#template_name: 2 Columns
#html: Left
#html: Right
#site: default, abc
%>
...
This template will be usable by the default site, as well as the multisite with the short name of "abc".