-
-
Notifications
You must be signed in to change notification settings - Fork 406
How to create or use a theme in Spina
This example will show you how to use a single page bootstrap theme as a template for Spina. The following steps are required
-
Download a theme that includes the HTML template and all the assets. I picked http://startbootstrap.com/template-overviews/grayscale/
-
unzip the file somewhere - outside of your spina folder.
-
We are going to replace the default theme in this example.
-
From the downloaded bootstrap theme - copy the index.html file over on top of the default page layout.
[spina-project-folder]/app/views/layouts/default/application.html.erb
-
edit application.html.erb and replace all the lines that include stylesheets and Javascript with the following
<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %>
<%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
<%= csrf_meta_tags %> -
from your bootstrap folder take each of the following folders 'img', 'js' and 'css' and move them to the following locations 'app/assets/images/default/', 'app/assets/javascripts/default/', 'app/assets/stylesheets/default' respectively.
-
rails s
and go over to your website. You should have the theme displayed.
We will now modify the theme pages so your content gets displayed. Before we being read up on how Spina does page layout and contents first from the Spina Readme. To summarize
- Page Layouts are defined in
config/initializers/themes/default.rb
for the default theme. - Each Page in Spina is based on a view template defined in this file under
self.view_templates = {...}
- Each view template includes multiple content fields (page_parts) defined under
self.page_parts = [...]
. Think of these as fields in a WP custom post type if you are coming from Wordpress. - Each content field can be added to a view template in the file with the
page_parts:[...]
setting. - When you create a new page in Spina, you pick the view template under the Advanced tab of the page editor using the Page Template field. IMHO this should not be an advanced setting but likely available upfront for selection.
- edit the
app/views/layouts/default/application.html.erb
that you had copied over. - find and replace the main content in this page with <%= yield %> since the actual rendering of the page content will be done elsewhere.
- edit the content layout under
app/views/[default]/pages/[homepage].html.erb
. Note that default and homepage are the names of your theme and view template. - Assuming we are still changing the homepage layout under the default theme continue on.
- Edit the file above and add the HTML you removed from
application.html.erb
in step 2 above into this file. - Within this
homepage.html.erb
file find the location where you need to display your page content and insert the following<%= @page.content(:content).try(:html_safe) %>
- If you have added multiple page_parts or fields to your page then you can print them the same way by replacing
:content
with the:page_part_name
Reload your website and you should be able to see your new theme.
- The page title is available as
<%= @page.title %>
for you to display - The menu is available as
<%= render 'spina/shared/navigation' %>
as a list. If you need to render this differently you can look up the navigation partial and change it as required. - You can add other variables to your view template as page_parts such as color, photo, gallery, line of text. These you can then insert into your view by using
@page.content(:page_part_name)
wherepage_part_name
is the name of page part in the configuration file.