Skip to main content
Sitemap

Get started

With the NHS.UK Eleventy Plugin you can start writing documentation rather than spend time building a website.

Use this plugin to create and publish documentation and other simple websites for people working in the NHS England.

This plugin includes the following features:

  • a set of layouts that use nhsuk-frontend components and styles

  • a way to set up common features like a sitemap, tags, RSS feeds and search

  • ensures pages uses the same typography and styles as those used on NHS.UK

  • support for Markdown and an extended syntax

  • full configuration of your website’s header and footer

  • SCSS compilation (for any files with the .scss extension)

Requirements

We recommend Node version manager if you are working across projects that use different versions of Node.js.

Installation

To install both Eleventy and this plugin, in your terminal type:

npm init -y

to create a new Node.js project. Then type:

npm install @11ty/eleventy @x-govuk/nhsuk-eleventy-plugin

Next, add an eleventy.config.js file to the root directory of your project. You will use this file to configure Eleventy, and set options for the plugin.

import { nhsukEleventyPlugin } from '@x-govuk/nhsuk-eleventy-plugin'

export default function(eleventyConfig) {
  // Register the plugin
  eleventyConfig.addPlugin(nhsukEleventyPlugin)

  return {
    dataTemplateEngine: 'njk',
    htmlTemplateEngine: 'njk',
    markdownTemplateEngine: 'njk',
    dir: {
      // The folder where all your content will live:
      input: 'docs',
    }
  }
};

To generate a site, type the following command:

npx eleventy --serve

Once Eleventy has generated all the files, the terminal will show a preview URL which you can enter into your browser’s address bar:

[11ty] Copied 14 files / Wrote 0 files in 1.11 seconds (v2.0.0)
[11ty] Watching…
[11ty] Server at http://localhost:8080/

Whenever you add a new page, or edit an existing one, the browser will automatically refresh with any of your changes applied.

Create a folder

You can now create a folder to contain all the content for your site, for example docs.

Add your chosen folder name to the input key within the eleventy.config.js file.

Create your first page

You’re now ready to start adding pages to your site.

Pages have 2 parts: a front matter and its contents.

A front matter starts and ends with --- and uses a key/value data format called YAML. In most cases, you will need 2 bits of information: layout and title. For example:

---
homepage: true
layout: page
title: My first page
---
This is my first page, built using Eleventy and `@x-govuk/nhsuk-eleventy-plugin`.

Create a file named index.md file within the folder you created, and add the above content.

The first page in your site should also have a homepage value set to true1. Eleventy uses this to work out the structure of your site if it has nested pages.

Open the preview URL in your browser to see this new page appear using NHS.UK styles.

Choose a layout

This plugin provides 7 different layouts, each with different options you can provide in the front matter:

  • Page – Simple layout designed for maximum flexibility of content.

  • Page with sub navigation – Layout with sub navigation.

  • Post – Layout for date-based content, such as blog posts or news items.

  • Collection – Layout for a paginated list of pages.

  • Error – Layout for an error page.

  • Hub – Layout for a hub page.

  • Product page – Layout for product and marketing pages.