Skip to main content

CCS GOV.UK Frontend Jinja Macros

PyPI version govuk-frontend 5.4.0 Python package

This is a fork of GOV.UK Frontend Jinja Macros which has not been updated beyond GOV.UK Frontend v5.1. This is for use in the Digital Marketplace until it starts to get updated again.

GOV.UK Frontend Jinja is a community tool of the GOV.UK Design System. The Design System team is not responsible for it and cannot support you with using it. Contact the maintainers directly if you need help or you want to request a feature.

This repository provides a complete set of Jinja macros that are kept up-to-date and 100% compliant with the original GOV.UK Frontend Nunjucks macros. Porting is intentionally manual rather than automated to make updates simpler than maintaining an automated conversion routine. A comprehensive test suite ensures compliance against the latest, and every subsequent, GOV.UK Frontend release.

Compatibility

The following table shows the version of CCS GOV.UK Frontend Jinja that you should use for your targeted version of GOV.UK Frontend:

CCS GOV.UK Frontend Jinja Version Target GOV.UK Frontend Version
1.7.0 5.11.0
1.6.0 5.10.0
1.5.0 5.9.0
1.3.0 5.7.1
1.2.2 5.5.0
1.2.1 5.4.1
1.2.0 5.4.0
1.1.0 5.4.0
1.0.0 5.3.1

Any other versions of GOV.UK Frontend not shown above may still be compatible, but have not been specifically tested and verified.

Use GOV.UK Frontend Jinja Macros for older versions of GOV.UK Frontend

How to use

After running pip install ccs-govuk-frontend-jinja, ensure that you tell Jinja where to load the templates from using the PackageLoader as follows:

from flask import Flask
from jinja2 import ChoiceLoader, PackageLoader, PrefixLoader

app = Flask(__name__)

app.jinja_loader = ChoiceLoader(
    [
        PackageLoader("app"),
        PrefixLoader({"govuk_frontend_jinja": PackageLoader("govuk_frontend_jinja")}),
    ]
)

Calling a Macro in your template

To use a component in your project templates you must import and call the component macro and pass the relevant options, for example:

{%- from 'govuk_frontend_jinja/components/button/macro.html' import govukButton -%}

{{ govukButton({
  'text': "Save and continue"
}) }}

The options available to each component macro can be found in the original GOV.UK Design System Components documentation. Since this project is a like-for-like port, the only difference between the Nunjucks examples and their Jinja equivalents is having to quote key names, e.g. 'text' instead of text.

Running the tests

The tests are run in a GitHub actions pipeline and you can run them locally with pytest.

You will need to download the GOV.UK Frontend package via npm with:

npm i

You can install the requirements for your chosen version of Python with:

pip install -r requirements-test-<YOUR_PYTHON_VERSION>.txt

You can then run the tests with:

pytest

The tests compare the HTML for each component fixture, which are within the GOV.UK Frontend package, with HTML generated by the Jinja macros.

Versioning

Releases of this project follow semantic versioning, ie

Given a version number MAJOR.MINOR.PATCH, increment the:

  • MAJOR version when you make incompatible API changes,
  • MINOR version when you add functionality in a backwards-compatible manner, and
  • PATCH version when you make backwards-compatible bug fixes.

To make a new version:

  • update the version in the digitalmarketplace_frontend_jinja/__init__.py file
  • if you are making a major change, also update the change log;

When the pull request is merged a GitHub Action will tag the new version.

Pre-commit hooks

This project has a pre-commit hook to do some general file checks and check the pyproject.toml. Follow the Quick start to see how to set this up in your local checkout of this project.

Licence

Unless stated otherwise, the codebase is released under the MIT License. This covers both the codebase and any sample code in the documentation.

The documentation is © Crown copyright and available under the terms of the Open Government 3.0 licence.

Metadata

Release files for ccs-govuk-frontend-jinja 1.7.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for ccs-govuk-frontend-jinja 1.7.0
File Size Uploaded Provenance Actions
ccs_govuk_frontend_jinja-1.7.0.tar.gz 31.2 kB Without provenance Details for ccs_govuk_frontend_jinja-1.7.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for ccs-govuk-frontend-jinja 1.7.0
File Interpreter ABI Platform Actions
ccs_govuk_frontend_jinja-1.7.0-py3-none-any.whl Python 3 none any Details for ccs_govuk_frontend_jinja-1.7.0-py3-none-any.whl

Total release size: 79.1 kB

Release files / ccs_govuk_frontend_jinja-1.7.0.tar.gz

Download URL ccs_govuk_frontend_jinja-1.7.0.tar.gz
Size 31.2 kB
Tags Source
SHA-256 checksum
How to use checksums
d541fc9b1526969820b1417057646fe18729ace946b6427286e81f57a720c3b4
BLAKE2b-256 checksum
How to use checksums
8c687d5b0b165d1a9a68776210ed7502bae3b330512bffe882e3c07020d65e8e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.11.13

Release files / ccs_govuk_frontend_jinja-1.7.0-py3-none-any.whl

Download URL ccs_govuk_frontend_jinja-1.7.0-py3-none-any.whl
Size 47.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
132de2bd12deec3faed15e97fa87e293def1d7e3c7537f31d4601fd29fb21214
BLAKE2b-256 checksum
How to use checksums
51c25aba395b6ff69c1448f57dcd391221875763c4f4d10e1f4f6b4301fd8d74
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.11.13

Security for ccs-govuk-frontend-jinja 1.7.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page