Central to CKAN’s functionality and user experience are its templates, which define the layout and presentation of web pages within the CKAN portal. These templates are constructed using a combination of HTML, CSS, and the Jinja2 templating language, offering a flexible framework for customising the appearance and behaviour of CKAN interfaces.

Updating CKAN templates is critical for maintaining the relevancy, accessibility, and aesthetics of a CKAN instance. Whether the goal is to align the portal’s look and feel with organisational branding, enhance user navigation, or incorporate new features, proficient management of CKAN templates ensures that data is presented in a user-friendly and engaging manner.

Modifying CKAN Templates

When updating CKAN templates, it is often necessary to modify the plugin.py file associated with your CKAN extension. This file is crucial for defining and registering custom templates, ensuring that CKAN recognizes and utilises the updated versions. 

The plugin.py file is part of your CKAN extension and is used to register plugins with CKAN. It tells CKAN which templates to use and can override default templates with custom ones. 

In plugin.py, you need to implement the IConfigurer interface, which allows you to specify additional directories for CKAN to search for templates. This is typically done by modifying the update_config method.

In our example after generating  the ckanext-pigeon extension, we uncomment the relevant lines from the plugin.py file as follows:

We now have a folder to place our custom template artefacts. CKAN will prioritise these templates over the default ones if they have the same name and the same relative path.

For this example, we will modify the footer page to use a new image that will be displayed at the bottom of all relevant pages. Specifically for our example, we add the footer.html file into templates/ folder. 

Here is the footer.html file:

Here we see that the image file pigeon.footer.jpg is inserted into the footer

Testing Changes:

After updating plugin.py and adding your custom templates and images, restart (or just trigger) your CKAN instance and verify that the changes are reflected. Ensure that the new templates load correctly and that there are no errors in the logs.

That’s it! You can also watch the 6-minute video on Link Digital YouTube Channel

In case you missed the previous tutorials, go to the main article to explore more topics.


Related articles

How to install CKAN using Docker Containers

How to install DataStore and DataPusher on CKAN

Create a CKAN development environment and install a new extension