Skip to main content

Set page titles

Information:

This feature requires version 6.3.0 of the NHS prototype kit or above.

The page title (<title>) is displayed in the browser tab.

The NHS Digital service manual has guidance on writing page titles.

To follow this guidance, set the first part of the page title by setting the pageName variable somewhere at the top of your view template:

{% set pageName = "Register with a GP" %}

This will be used along with the serviceName set in config.js to generate a page title with this format:

Register with a GP - Service name goes here - NHS

As the page name used in the title will often be the same as the <h1> heading, you can re-use the same variable there to ensure consistency:

{% set pageName = "Register with a GP" %}

{% block content %}
  <h1>{{ pageName }}</h1>
{% endblock %}

Adding an error prefix

If your prototype includes validation error messages, you can set the errors variable to include an error prefix in the page title:

{% set pageName = "Your previous address" %}
{% set errors = true %}

This will generate the page title:

Error: Your previous address - Service name goes here - NHS

The error prefix will also be included if the errors variable is set to a non-empty string, array or object

Custom page title formats

If you need to use a different page title format, you can do so by overriding the pageTitle block in your layout.html file.

For example:

{% block pageTitle -%}
  {{ pageName }} - NHS {{ serviceName }}
{%- endblock %}