Using Law Widgets to add styles to document content
Customising styles with CSS
Law Widgets
Akoma Ntoso HTML documents don't look very good without styling. Laws.Africa's Law Widgets is a collection of web components that make it simple to style the HTML provided by the Laws.Africa Content API.
Using Law Widgets is easy:
Add a reference to the Law Widgets javascript.
Use the law widgets in your HTML.
We'll use the <la-akoma-ntoso> widget to apply appropriate styles to the expression HTML in expression_detail.html.
expression_detail.html
<html><head><title>{{ expression.title }}</title><!-- add the law widgets javascript --> <scripttype="module"src="https://cdn.jsdelivr.net/npm/@lawsafrica/law-widgets@latest/dist/lawwidgets/lawwidgets.esm.js" ></script></head><body><ahref="{% url 'home' %}">Home</a><h1>{{ expression.title }}</h1><!-- use la-akoma-ntoso law widget to apply styles --><la-akoma-ntosofrbr-expression-uri="{{ expression.frbr_uri }}"> {{ expression.content|safe }}</la-akoma-ntoso></body>
If you refresh your expression page in your browser, you should now have a well-styled document.
We included the frbr-expression-uri attribute on the <la-akoma-ntoso> element. If you inspect the <la-akoma-ntoso> element in your browser's inspector, you'll see that new attributes have been added automatically:
These additional attributes are derived from the Expression FRBR URI. They allows Law Widgets (and you) to customise the applied styles depending on a country's legal tradition.
For example, in Namibia's legal tradition editorial comments are green and bold. This styling is applied based on CSS selectors that work on the FRBR attributes added above.