HTML Components
A version of the design system implemented as HTML Templates components is currently under development.
These are idiomatic components suitable for applications developed with Nunjucks
or Jinja.
Note that the HTML components are currently under design review. Component designs and implementations will change over time, but any breaking changes will be handled with major version increments.
We are also reviewing mechanisms to abstract away the underlying HTML markup when consuming components to simplify updates as components change.
Please check the current status of each HTML component for latest updates.
Install using precompiled files
You can install the Gov IE Frontend global HTML components by copying the CSS, JavaScript, and macro files into your project.
Download the files
- Download the
govie-frontend.zip
asset file from the latest release of@govie-ds/html
. - Download the
theme.zip
asset file from the latest release of@govie-ds/theme-govie
.
Integration with Wagtail
Copy CSS and JavaScript
- Copy the
theme.css
file fromtheme.zip
to a folder that can serve static CSS files, e.g.static/css
. - Copy the
styles.css
file fromgovie-frontend.zip
to a folder that can serve static CSS files, e.g.static/css
. - Copy the
govie-frontend.umd.js
file fromgovie-frontend.zip
to a folder that can serve static JavaScript files, e.g.static/js
.
Copy Jinja macros
- Copy the
macros
folder fromgovie-frontend.zip
file to a location that can be configured with Jinja.
The
macros
folder contains bothdev
andprod
versions of Jinja macros. You should configure Wagtail to use thedev
macros in non-prod environments, and theprod
macros in production.
Configure Jinja templates in Wagtail
- Configure Jinja to serve static files within templates, e.g. create a Jinja environment file:
from django.templatetags.static import static from jinja2 import Environment def environment(**options): env = Environment(**options) env.globals.update({ 'static': static, }) return env
- Update your Wagtail settings to configure Jinja templates, including the folder for the macros, and a folder for you application templates, and your Jinja environment for serving static files:
TEMPLATES = [
{
"BACKEND": "django.template.backends.django.DjangoTemplates",
"DIRS": [
os.path.join(PROJECT_DIR, "templates"),
],
"APP_DIRS": True,
"OPTIONS": {
"context_processors": [
"django.template.context_processors.debug",
"django.template.context_processors.request",
"django.contrib.auth.context_processors.auth",
"django.contrib.messages.context_processors.messages",
],
},
},
{
'BACKEND': 'django.template.backends.jinja2.Jinja2',
'APP_DIRS': True,
"DIRS": [
os.path.join(PROJECT_DIR, "jinja"),
os.path.join(PROJECT_DIR, "macros/jinja/dev"),
],
'OPTIONS': {
'extensions': [
'wagtail.jinja2tags.core',
'wagtail.admin.jinja2tags.userbar',
'wagtail.images.jinja2tags.images',
],
'environment': 'core.jinja2-env.environment',
},
}
]
Specify the appropriate folder paths to your application Jinja templates, the Gov IE Frontend global HTML macros, and your Jinja environment file for serving static assets.
- Create a Jinja template that uses a Gov IE Frontend global HTML macro in your Jinja templates folder:
{% from 'govie/header/macro.html' import govieHeader %} <!doctype html> <html lang="en"> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <title>{{ page.title }}</title> <link rel="stylesheet" href="{{ static('css/theme.css') }}" /> <link rel="stylesheet" href="{{ static('css/styles.css') }}" /> </head> <body> {{ govieHeader({ 'title': 'Application title' }) }} <h1>{{ page.title }}</h1> <script src="{{ static('js/govie-frontend.umd.js') }}"></script> </body> </html>
Note that the template needs to include the
theme.css
,styles.css
, andgovie-frontend.umd.js
files previously copied to a folder that can serve static files.