Skip to main content

register_templates

Function register_templates 

Source
pub fn register_templates(tera: &mut Tera) -> Result<(), Error>
Expand description

Register the bundled admin templates and the Tera helpers they depend on (named URL reversal via {{ url(...) }}, the {% querystring %} filter, humanize filters, and the csrf_input filter) on a Tera instance.

Host apps call this once during Tera setup so the admin handlers can find their templates without filesystem access.

§Customizing the admin

Drop a Tera template at templates/cms_admin/<template-name>.html in your project root to override the bundled CMS admin template of the same name. The override walk runs after the bundled defaults register, so a host file wins over the built-in copy via Tera’s name-collision semantics.

Directory layout mirrors the template namespace:

templates/cms_admin/
  login.html                 → overrides "login.html"
  _auth_layout.html          → overrides "rcms_admin/_auth_layout.html"
  rcms_admin/_base.html      → overrides "rcms_admin/_base.html"
  blocks/heading.html        → overrides "blocks/heading.html"

Top-level .html files at templates/cms_admin/*.html get a best-fit name: the bare basename is used as the Tera template name (so login.html overrides the framework’s login, and _auth_layout.html overrides the bundled rcms_admin/_auth_layout.html via an explicit aliased registration). Files in nested subdirectories use their relative path (e.g. blocks/heading.html).

Customizing the stylesheet uses the same pattern but with static/cms_admin/cms.css (the bundled CSS handler does its own override discovery at request time — see serve_cms_css).

§Errors

Propagates Tera errors from template registration (only fails on internal parse errors of the bundled templates, which would be a compile-time bug in this crate, not a runtime concern) and I/O errors when reading an unreadable host override.