A port of NHS.UK frontend templates for the Jinja templating engine.
Project description
NHS.UK frontend jinja templates
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 |
| 10.3.1 | 0.7.2 |
| 10.4.0 | 0.8.0 |
| 10.5.0 | 0.9.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
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file nhsuk_frontend_jinja-0.9.0.tar.gz.
File metadata
- Download URL: nhsuk_frontend_jinja-0.9.0.tar.gz
- Upload date:
- Size: 76.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
aa021fd8b13db2e82bf6f3e83dddbec6792d6960d00d7436845d951089b846be
|
|
| MD5 |
520d631e74c6f9ecd7ee972ee55b053c
|
|
| BLAKE2b-256 |
fe67433bd9a9dd73abc3f7e0d54fe0bfc2f8bb7a90311f81470cad53d5d73010
|
Provenance
The following attestation bundles were made for nhsuk_frontend_jinja-0.9.0.tar.gz:
Publisher:
publish.yml on NHSDigital/nhsuk-frontend-jinja
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
nhsuk_frontend_jinja-0.9.0.tar.gz -
Subject digest:
aa021fd8b13db2e82bf6f3e83dddbec6792d6960d00d7436845d951089b846be - Sigstore transparency entry: 1939836792
- Sigstore integration time:
-
Permalink:
NHSDigital/nhsuk-frontend-jinja@3851aefeb33d9f30577d1b34b8bd5da532b47d0f -
Branch / Tag:
refs/tags/v0.9.0 - Owner: https://github.com/NHSDigital
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@3851aefeb33d9f30577d1b34b8bd5da532b47d0f -
Trigger Event:
push
-
Statement type:
File details
Details for the file nhsuk_frontend_jinja-0.9.0-py3-none-any.whl.
File metadata
- Download URL: nhsuk_frontend_jinja-0.9.0-py3-none-any.whl
- Upload date:
- Size: 68.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5c4bde8c309efa21a981b1f1d6dc276b749dedb27d7a107f9bf71dafb6fcea89
|
|
| MD5 |
7f58fa5581efa0ae01cb2fa39b4ede2b
|
|
| BLAKE2b-256 |
e8ea645d0ba1fdd50d04b5001ecbae5273690321bd18c59d3aaf32edd1d60199
|
Provenance
The following attestation bundles were made for nhsuk_frontend_jinja-0.9.0-py3-none-any.whl:
Publisher:
publish.yml on NHSDigital/nhsuk-frontend-jinja
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
nhsuk_frontend_jinja-0.9.0-py3-none-any.whl -
Subject digest:
5c4bde8c309efa21a981b1f1d6dc276b749dedb27d7a107f9bf71dafb6fcea89 - Sigstore transparency entry: 1939836890
- Sigstore integration time:
-
Permalink:
NHSDigital/nhsuk-frontend-jinja@3851aefeb33d9f30577d1b34b8bd5da532b47d0f -
Branch / Tag:
refs/tags/v0.9.0 - Owner: https://github.com/NHSDigital
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@3851aefeb33d9f30577d1b34b8bd5da532b47d0f -
Trigger Event:
push
-
Statement type: