Templating easy
InvenioRDM uses Jinja templates as the primary mechanism for rendering server-side HTML.
Templating allows you to redefine page layouts, override sections of existing pages, or introduce entirely new pages into your repository UI.
With InvenioRDM 14+, templating interacts closely with the theming system, which determines which templates are used for each view and how they are combined with assets, configuration, and extensions.
This page explains how template resolution works, how to override templates, and how the inheritance hierarchy shapes the final rendered interface.
Understanding Template Layers in NRP Invenio Repositories
InvenioRDM provides a layered template system composed of:
-
Invenio-Theme base templates
Provide the general HTML skeleton (layout, header/footer blocks, page wrappers). -
Invenio-App-RDM (RDM) templates
Define page-level templates for record detail, search, deposit, homepage, and more. -
Oarepo UI templates (NRP base templates)
Extend and customize some RDM templates with NRP-specific branding, components, and layouts. -
Instance templates (your repository)
Templates you add under your instance’s registeredtemplates/folder override any matching upstream template. -
Model-specific templates (per each of your record model)
Each record model may introduce their own templates that extend or override base RDM templates to customize the UI for records of that specific model type.
This layering follows the same customization hierarchy as other parts of the theming system.
The rule is simple: your templates always take precedence over the ones shipped by libraries and modules.
See also:
InvenioRDM Customization Hierarchy
https://inveniordm.docs.cern.ch/operate/customize/#customization-hierarchy
Changing the Templates
Which templates are used for each page is primarily controlled by the configuration variables in
Invenio application configuration (e.g. invenio.cfg).
Template-related configuration keys typically end with _TEMPLATE, for example:
THEME_BASE_TEMPLATEHEADER_TEMPLATERDM_SEARCH_TEMPLATECOMMUNITIES_BASE_TEMPLATE
To change a template, you have 2 options:
1. Using application configuration
For cases supported by Invenio application configuration, you can change a path to a template by setting a corresponding option.
- Create a new template file under your instance’s
templates/folder. - Set the corresponding config variable (if applicable) to point to your template.
- Ensure the path is given relative to the registered templates directory.
2. Using same relative path as original
This method allows to override basically any template used in your site. Create a file with the same path relative to templates as the original. See InvenioRDM Customize Templates docs for more.
Template Locations and Resolution
All templates are resolved by searching through the registered template folders in the order governed by the Flask application bootstrap.
For instance, if you define:
- myfooter.html
Then any reference to custom/myfooter.html in your configuration will resolve to that file.
If a module (e.g., invenio-app-rdm) also ships a custom/myfooter.html (sharing the same relative path under the templates folder), your instance’s version automatically overrides it.
Template Inheritance and Composition
Jinja provides powerful mechanisms for composing templates via template inheritance.
A common pattern is that a base template defines structural blocks:
{% block page_header %}{% endblock %}
{% block page_content %}{% endblock %}Then, child templates extend the base and fill in those blocks:
{% extends "base.html" %}
{% block page_header %}
<h1>My Custom Header</h1>
{% endblock %}
{% block page_content %}
<p>This is my custom content.</p>
{% endblock %}In NRP Invenio repositories, most templates follow this pattern, allowing you to override just the parts you need while reusing common layout and structure from upstream templates. Base page layout is provided by the Oarepo-UI package and extended in child templates by referencing it as {% extends "oarepo_ui/base_page.html" %}.
Example: Overriding a Footer Template
1. Create Your Custom Footer Template
{% extends "invenio_app_rdm/footer.html" %}
{% block footer_right %}
<p>Custom footer text for my repository.</p>
{% endblock %}2. Configure Your Repository to Use the Custom Footer
invenio.cfg
THEME_FOOTER_TEMPLATE="custom/myfooter.html"This just scratches the surface of what you can achieve with templating in NRP Invenio repositories. For a more in-depth Jinja template development reference, please head over to the Jinja templates section.