
Security News
Crates.io Users Targeted by Phishing Emails
The Rust Security Response WG is warning of phishing emails from rustfoundation.dev targeting crates.io users.
nhsuk-frontend-jinja
Advanced tools
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.
pip install nhsuk-frontend-jinja
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 |
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"),
]
),
}
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"),
]),
**options)
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.
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.
Read our contributing guidelines to contribute to NHS.UK frontend jinja.
This repo is maintained by NHS England. Open a GitHub issue if you need to get in touch.
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.
FAQs
A port of NHS.UK frontend templates for the Jinja templating engine.
We found that nhsuk-frontend-jinja demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
The Rust Security Response WG is warning of phishing emails from rustfoundation.dev targeting crates.io users.
Product
Socket now lets you customize pull request alert headers, helping security teams share clear guidance right in PRs to speed reviews and reduce back-and-forth.
Product
Socket's Rust support is moving to Beta: all users can scan Cargo projects and generate SBOMs, including Cargo.toml-only crates, with Rust-aware supply chain checks.