Spree Commerce

Try It Now

Improved Layout Customization

Posted on July 27, 2009 by Sean Schofield

The edge version of Spree has new features aimed at reducing the need to override the default Spree layout template. The title, stylesheets, and logo now can all be customized without creating your own copy of the layout. These handy new features were contributed by Eliot Sykes along with the following writeup.

New Title Methods

There are some new methods for manipulating the page title: the title and set_title helper methods in Spree::BaseController.

Use set_title to set a page title either from a controller method, or a view template. You can also override the default_title and title methods in Spree::BaseController for further control.

The title method is used in application.html.erb of the new release, however if you are upgrading and want to take advantage, use this in between your <title> tags of your layout template:


<p>&lt;%= title %&gt;</p>

And to set the title in a view template:


<p>&lt;% set_title &#8216;My custom title&#8217; %&gt;</p>

Customize Default Stylesheets

Spree::Config[:stylesheets] is a new config option for customizing the stylesheets used by the default application layout.

The value of Spree::Config[:stylesheets] is a comma-separated string
of stylesheet names without the file extensions. See the customization
tutorial
for more information.

If you are upgrading, to take advantage of this use the new stylesheet_tags helper method.

Customized Logo

Spree::Config[:logo] is a new config option for customizing the logo image path. If you are upgrading, take advantage of this by using the new logo helper method.

blog comments powered by Disqus