For the complete documentation index, see llms.txt. This page is also available as Markdown.

Templates

Administrative endpoints for stored templates — the template sources kept in the database and rendered in place of the template files shipped with the project. They are how the markup of an email, an SMS message or a storefront page is changed for a single store, or per language, without a deployment.

A stored template does not introduce a new template: it overrides an existing one. Its name is the path of the template file it stands in for — emails/orders/completed.html, for example — and each record is bound to one language and to one or more sites. When that template is rendered, the stored source is used if a record matches the name, the language of the request and the current site; otherwise the file on disk is used, so removing or deactivating a record restores the original template.

Core Capabilities

1. Listing & Filtering

  • Retrieve a paginated list of stored templates, ordered by name ascending unless the sort parameter says otherwise.

  • Filter by name, by active state and by site. Names match the whole value exactly; a partial name returns an empty page.

  • Deactivated templates stay in the list — filter on is_active to separate them from the ones in use.

2. Full CRUD

  • Store a template for a language and one or more sites, fully or partially update it, and deactivate it.

  • DELETE deactivates the record rather than removing it. See Deleting a Template for what that means for the name.

3. Overridable Template Names

  • The names of the email and SMS templates the platform sends are listed by a dedicated operation, so a client does not have to know the template paths in advance.

4. Site & Language Binding

  • A name is normally stored once per language and site, which is what allows one store to override a template for one language only. See Uniqueness for the case where that rule is not enforced.

How a Stored Template Is Used

Storing a record is not by itself enough for it to be rendered. All of the following must hold at the moment the template is rendered:

Condition
Detail

The database loader is enabled

The template engine of the deployment must be configured to look in the database. See Dynamic Settings & Environment Variables — in a deployment that is not configured for it, stored templates are accepted by these endpoints but never rendered.

The name matches exactly

The name must equal the path of the template being rendered, extension included. A name that differs by a character, or that is missing the extension, overrides nothing.

The record is active

A record whose is_active is false is skipped, and the template file is used instead.

A site matches

The record must list the site the request is served for. A record with no sites is never rendered.

The language matches

The record must be stored for the language of the request. When no record exists for that language, the record stored for the default language of the deployment is used; when there is none, the template file is used.

Two further points are worth knowing:

  • Names beginning with admin/ are never served from the database. Management-panel templates are always read from disk.

  • Changes are not visible immediately. The lookup is cached — for up to five minutes in a standard deployment — so a newly stored, updated or deactivated template takes a few minutes to take effect on the storefront. This applies to deactivation as well. A deployment that also configures the shorter cache layers of the platform stacks a one-minute and a three-minute layer in front of that one, which can stretch the wait further.

Fields

Field
Description

pk

Unique identifier of the record. Assigned by the server; ignored if sent.

name

The path of the template being overridden, at most 100 characters. Required. Surrounding whitespace and any leading slashes are removed before the value is stored, so /emails/base.html is stored as emails/base.html.

content

The template source. Required and may not be empty. It is stored as sent and is not checked for syntax errors, so a record with a broken template is accepted here and fails when the template is rendered.

language

The language the record applies to. Required, and must be one of the languages configured for the deployment.

is_active

Whether the record is used when the template is rendered. Optional; defaults to true.

sites

The sites the record applies to, given as an array of site identifiers. Optional — see Site Binding for what omitting it means on each operation.

created_date

When the record was created. Read-only.

modified_date

When the record was last modified. Read-only.

Site Binding

The sites array behaves differently on each operation, and an empty array is not a way to clear it:

Operation

Behaviour when sites is omitted or empty

Create

The record is bound to the current site of the request.

Full and partial update

The stored sites are left untouched. There is no way to unbind every site through these endpoints; send the sites the record should apply to instead.

A non-empty array replaces the stored sites completely rather than adding to them. Every identifier must belong to an existing site; an unknown identifier fails the request.

Uniqueness

A name is meant to be stored only once per site and language. A create or update that repeats an existing combination is rejected with a message naming the site and the language that conflict; the message is returned in the language of the request, so match on the response status rather than on its wording.

The check covers deactivated records too, so a name occupied by a deactivated record cannot be stored again — see Deleting a Template.

Which sites the check runs against depends on the request:

Request
Sites checked

Create without sites

The current site of the request.

Create or update with a non-empty sites

The sites in the request.

Update without sites

The sites the record is already bound to.

Any request with an empty sites array

None — and with no site to check against, the check is skipped entirely.

Important: Send these requests as JSON. A form-encoded request always carries sites as an empty array, even when the field is left out of the form, and the uniqueness check is therefore never applied to it: the duplicate is accepted and stored. Two records with the same name, language and site break the storefront lookup for that template, because the lookup expects at most one.

Deleting a Template

Important: DELETE does not remove the record. It sets is_active to false and returns 204 No Content; the record keeps appearing in the list and can be retrieved by its identifier.

Two consequences follow. The template file on disk takes over again once the cached lookup expires, which is the intended effect. But the name stays occupied: storing the same name for the same site and language again is rejected, and the way to bring the template back is to set is_active to true on the existing record rather than to create a new one.

Partially Updating a Name

When a partial update changes name, include language in the same request. A partial update that sends name without language cannot complete the uniqueness check and fails with a server error — unless there is no site to check against, in which case the check does not run and the request succeeds. A full update is unaffected, because language is required there.

Sorting

The sort parameter accepts pk, name, content, language, is_active, created_date and modified_date. Prefix a field with a hyphen for descending order. Any other value is ignored and the default ordering by name is kept.

Do not sort by sites. The value is accepted, but a record bound to several sites is then repeated once per site while the page count keeps counting records rather than rows — so the page fills up with repetitions and other records fall off it entirely.

Sorting by content is accepted too and orders records by their raw template source, which rarely produces a useful order.

Dynamic Settings & Environment Variables

No dynamic setting changes the behaviour of the endpoints described here: every action stays available and behaves identically regardless of how the settings are configured. The two settings below relate to the templates managed here at the point where they are used.

Key
Type
Default
Effect

DB_TEMPLATES_PREFIXES

array of strings

["emails", "sms"]

Deprecated and without effect. It once did two things: it rejected a name whose first path segment was not one of these prefixes, and it kept the database from being consulted for any other template. Both checks were removed, and the value is no longer read anywhere — a name under any prefix is stored and overrides its template all the same.

DISABLED_EMAIL_TEMPLATES

object mapping a template path (without its extension) to a boolean

every email template enabled, except the order-preparing email, which is disabled

A per-template kill switch for outbound emails. It does not affect these endpoints — a template stored for a disabled email is created and returned normally — but the email is never sent, so the stored template is never rendered.

Environment variables: The following deployment configuration decides whether and how stored templates are used. None of it is read by these endpoints themselves, so a misconfigured deployment gives no error here.

Variable
Effect

TEMPLATE_LOADER

Decides whether stored templates are used at all. The database is consulted only while this is set to the loader that reads templates from the database and falls back to the files on disk (omnicore.dbtemplates.jinja_loaders.DatabaseAndFileSystemLoader); that is the default in a cloud-mode deployment. In a deployment that keeps the file-system-only loader — which is the default outside cloud mode — records created through these endpoints are stored but never rendered.

LANGUAGES

The languages a record may be stored for. A language outside this list fails validation. Given as comma-separated code=name pairs, for example tr-tr=Turkish,en-us=English.

LANGUAGE_CODE

The default language of the deployment, used as the fallback when no record is stored for the language of the request.

DB_TEMPLATES_MODEL

Selects which record type these endpoints manage. Unlike the three above it is not read from an environment variable but from the deployment configuration itself, and it is left unset in a standard deployment — the templates of the content-management module are managed then.

Last updated

Was this helpful?