Skip to main content

A port of NHS.UK frontend templates for the Jinja templating engine.

Project description

NHS.UK frontend jinja templates

Quality Gate Status

A Jinja implementation of the NHS.UK frontend components.

NHS.UK frontend contains the code you need to start building user interfaces for NHS websites and services.

Installation

pip install nhsuk-frontend-jinja

Compatibility

The following table shows the version of NHS.UK frontend jinja that you should use for your targeted version of NHS.UK frontend:

NHS.UK frontend version NHS.UK frontend jinja version
9.3.0 0.1.0
9.5.2 0.2.0
9.6.1 0.3.0
9.6.2 0.3.1
10.0.0 0.4.1
10.1.0 0.5.0
10.2.0 0.6.0
10.2.2 0.6.1
10.3.0 0.7.0

Configuration

Configure your Jinja environment to load templates from this package and use ChainableUndefined.

Flask example:

from jinja2 import FileSystemLoader, ChoiceLoader, PackageLoader, ChainableUndefined

app.jinja_options = {
    "undefined": ChainableUndefined,  # This is needed to prevent jinja from throwing an error when chained parameters are undefined
    "loader": ChoiceLoader(
        [
            FileSystemLoader(PATH_TO_YOUR_TEMPLATES),
            PackageLoader("nhsuk_frontend_jinja"),
        ]
    ),
    "autoescape": True
}

Plain Jinja example:

from jinja2 import Environment, FileSystemLoader, ChoiceLoader, PackageLoader, ChainableUndefined

jinja_env = Environment(
    undefined=ChainableUndefined,
    loader=ChoiceLoader([
        FileSystemLoader(PATH_TO_YOUR_TEMPLATES),
        PackageLoader("nhsuk_frontend_jinja"),
    ]),
    autoescape=True,
)

Alternatively, if you want to reference components without the 'nhsuk/components' or 'nhsuk/macros' prefixes, you can include additional PackageLoaders that specify package_path:

ChoiceLoader([
    FileSystemLoader(PATH_TO_YOUR_TEMPLATES),

    PackageLoader("nhsuk_frontend_jinja", package_path="templates/nhsuk/components"),
    PackageLoader("nhsuk_frontend_jinja", package_path="templates/nhsuk/macros"),

    PackageLoader("nhsuk_frontend_jinja"),
])

You should then be able to extend the default page template:

{% extends 'nhsuk/template.jinja' %}

{% block pageTitle %}Example - NHS.UK Frontend{% endblock %}

{% block content %}
{% endblock %}

See Page Template in the service manual for details of all the options.

Usage

Visit the NHS digital service manual for examples of components and guidance for when to use them.

All our macros take identical arguments to the Nunjucks ones, except you need to quote the parameter names.

{% from 'nhsuk/warning-callout/macro.jinja' import warningCallout %}

{{ warningCallout({
  "heading": "Quotey McQuoteface",
  "HTML": "<p>Don't forget to quote your parameter names!</p>"
}) }}

Note that all macro paths use the .jinja extension.

Contribute

Read our contributing guidelines to contribute to NHS.UK frontend jinja.

Development environment

Gitpod ready-to-code

Get in touch

This repo is maintained by NHS England. Open a GitHub issue if you need to get in touch.

Licence

The codebase is released under the MIT Licence, unless stated otherwise. This covers both the codebase and any sample code in the documentation. The documentation is © NHS England and available under the terms of the Open Government 3.0 licence.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

nhsuk_frontend_jinja-0.7.0.tar.gz (27.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

nhsuk_frontend_jinja-0.7.0-py3-none-any.whl (60.1 kB view details)

Uploaded Python 3

File details

Details for the file nhsuk_frontend_jinja-0.7.0.tar.gz.

File metadata

  • Download URL: nhsuk_frontend_jinja-0.7.0.tar.gz
  • Upload date:
  • Size: 27.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for nhsuk_frontend_jinja-0.7.0.tar.gz
Algorithm Hash digest
SHA256 5e0211b79809126bcabdd95349daeeca3a2e51c77fc1df75a68d07e735843286
MD5 4ad24efd2615070f77542a0f4195dd6e
BLAKE2b-256 1dc38f6ff1e98f13c2be6829b2254cb03955537291014533b6d8e345b9662931

See more details on using hashes here.

Provenance

The following attestation bundles were made for nhsuk_frontend_jinja-0.7.0.tar.gz:

Publisher: publish.yml on NHSDigital/nhsuk-frontend-jinja

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file nhsuk_frontend_jinja-0.7.0-py3-none-any.whl.

File metadata

File hashes

Hashes for nhsuk_frontend_jinja-0.7.0-py3-none-any.whl
Algorithm Hash digest
SHA256 905c10c17826e2415b2e8bd020be0dd296f328790b66bff87af5042cbe73dadd
MD5 d46d33feff0a18a68b34b347c3b20133
BLAKE2b-256 497dd701bc212e4274a1a736a046a7cfdf9053d84db086813a72f1edfe94e01e

See more details on using hashes here.

Provenance

The following attestation bundles were made for nhsuk_frontend_jinja-0.7.0-py3-none-any.whl:

Publisher: publish.yml on NHSDigital/nhsuk-frontend-jinja

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page