Add govuk_template
to your app's Gemfile
:
gem 'govuk_template'
(In a production system you'll want to pin a more specific version for stability)
Add this line to the bottom of your application layout view (usually in app/views/layouts/application.html.erb
):
<%= render file: 'layouts/govuk_template' %>
govuk_template
provides blocks you can insert content into, to customise the basic layout.
For example, to set a <title>
for your page you can set content for the :page_title
block, and it will be inserted into the govuk_template
layout.:
<% content_for :page_title, "My page title" %>
Or to add content to <head>
, for stylesheets or similar:
<% content_for :head do %>
<%= stylesheet_link_tag 'application', media: 'all' %>
<%= csrf_meta_tags %>
<% end %>
Check out the full list of blocks you can use to customise the template.
govuk_template
>= 20.0.0 can be used together with sprockets-rails
>= 3.0.0 in order to make use of the SRI
You can read more about SRI here.
SRI will add an integrity
attribute on your script tags:
<script src="https://example.com/example.css" integrity="sha384oqVuAfXRKap7fdgcCY5uykM6+R9GqQ8K/uxy9rx7HNQlGYl1kPzQho1wx4JwY8w" crossorigin="anonymous"></script>
The example above is generated automatically by sprockets-rails in your project if the integrity option is set to true:
<%= stylesheet_script_tag 'example', integrity: true %>
There is a bug in Firefox versions less than 52 which means it interprets the SRI hash incorrectly for CSS files that start with the UTF8 byte order mark (BOM). Sprockets-rails will include a UTF8 BOM in the compiled CSS file if any of the source stylesheets have UTF8 characters in them and this means Firefox < 52 will refuse to load these assets. To avoid this we developed the asset_bom_removal-rails gem to strip the UTF8 BOM from compiled CSS assets as part of the rails asset pipeline.