Skip to content

Writing website templates ​

Onivos builds pages two ways: the visual builder (drag & drop blocks) and code mode — a coded template you write by hand. This guide covers code mode: the template language, the data you can read, and how to keep coded pages editable.

Code mode uses the Onivos template language — HubL-flavoured Jinja, so it reads like the templates you may know from HubSpot or Jinja. Templates can read your site's data and loop/branch over it, but they cannot run arbitrary JavaScript, fetch anything, or run forever, so a template is always safe to publish. The full list of tags and filters is the template language reference.

When to use code mode

Reach for the visual builder for most pages. Switch a page to code mode when you want pixel-exact control, are pasting a hand-built HTML section, or need logic the blocks don't cover (loops, conditionals, dynamic data). You can mix both — see Keep regions editable below.

Your first template ​

A code-mode page is just HTML with template tags sprinkled in. Output a value with a double-brace output tag, and branch or loop with {% %} statements:

jinja
<section class="hero">
  <h1>{{ page.title }}</h1>
  <p>Welcome to {{ site.name }}.</p>

  {% if page.seo.description %}
    <p class="lede">{{ page.seo.description }}</p>
  {% endif %}
</section>

Empty values are false, so {% if page.seo.description %} skips the paragraph when there's no description — no empty tags in your output.

What you can read ​

Every template runs with these objects in scope:

ObjectWhat it holds
siteThe site itself: site.name, and raw injection points site.headHtml / site.bodyEndHtml.
pageThe current page: page.title, page.slug, page.lang, and page.seo.description.
themeBrand tokens: theme.colors.primary, theme.colors.bg, theme.colors.text, theme.radius, theme.font.
requestrequest.path, request.params (a dynamic page's path parameters, e.g. /blog/:slug → request.params.slug), request.query, request.locale.
dataThe output of the page's controller, when it has one.
local_dtThe time of the render — {{ local_dt|datetimeformat("%Y") }} for the footer year.

Anything else a page shows — blog posts, products, data-object records, menus, pricing — it declares at the top, and the platform loads it before the page renders:

jinja
{% data post = blog.post(slug=request.params.slug) %}
{% data related = blog.list(limit=3) %}

<h1>{{ post.title }}</h1>
<article>{{ post.content_html|sanitize_html }}</article>

<ul class="related">
  {% for item in related %}
    <li><a href="/blog/{{ item.slug }}">{{ item.title }}</a></li>
  {% endfor %}
</ul>

A declaration is checked when you save: the source must exist, its arguments must fit, and you must be allowed to publish what it reads. The page settings' Data source picker writes the declaration for a data object for you.

Filters ​

Filters transform a value — you pipe a value into a filter:

jinja
{{ 199000|money }}                             → formatted in your store currency
{{ page.title|default(site.name, true) }}      → falls back when the title is empty
{{ photo|image_url(width=800) }}               → a resized image URL
{{ classes|class_names }}                      → joins a list/map into a class string
  • money — format a minor-unit amount in the store's currency and locale.
  • default — a fallback when the value is missing (with true, also when it is empty).
  • image_url / image_tag — resized image URLs and responsive <img> tags.
  • class_names — build a class string from a list or a { class: condition } map.

The standard filters (upper, truncate, format_date, join, …) are all there too.

jinja
<div class="{{ ['card', 'card--wide' if is_featured else '']|class_names }}">
  {{ product.image|image_url(width=600)|image_tag(alt=product.name) }}
  <span class="price">{{ product.price|money }}</span>
</div>

Every value is escaped for where it lands — text, attribute, URL, style or script — so you never add an escape filter, and a javascript: link can never reach an href. Use |safe only for markup you trust.

Theme tokens as CSS variables ​

Your theme's brand tokens are emitted as CSS custom properties on every page, so you can style templates without hardcoding colors — re-skinning the theme restyles them:

html
<style>
  .cta {
    background: var(--onv-color-primary);
    color: var(--onv-color-bg);
    border-radius: var(--onv-radius);
    font-family: var(--onv-font);
  }
</style>
<a class="cta" href="/signup">Get started</a>

Available variables: --onv-color-primary, --onv-color-bg, --onv-color-text, --onv-radius, --onv-font.

Wrap in the site layout, or not ​

A code page can either sit inside your site layout (header + footer around it) or be the whole document — declared at the top of the code:

  • {% extends "layouts/theme.html" %} (the default for new pages): the theme's header, footer, <head>, and theme CSS wrap your template, and you fill the layout's regions with {% block main %}…{% endblock %} overrides.
  • No extends line: your template is the entire response — start from <!doctype html>. Use this to paste a complete, self-contained landing page. The page's own CSS/JS are still injected into <head> / before </body>.

Keep regions editable with {% dnd_area %} ​

A fully coded page isn't editable in the visual builder — unless you mark drop areas. Wrap a part of your template in {% dnd_area %} and give it a name; teammates can then drag blocks into that area visually, while the rest stays locked in code:

jinja
<section class="promo">
  <h2>This heading is fixed in code.</h2>

  {% dnd_area "promo-body" %}
    <p>Default content — shown until someone drops blocks here.</p>
  {% end_dnd_area %}
</section>

Blocks placed on the canvas are written into the area as {% dnd_module %} tags, and rows of columns as {% dnd_row %} / {% dnd_column width=6 %} on a 12-column grid — you can edit them in code too. This is the best of both worlds — a locked-down shell with editable pockets.

Building a reusable layout (advanced) ​

Themes can define a custom layout — the outer HTML shell wrapped around every page. A layout defines named {% block %} regions pages override, and places your global header/footer with {% global_partial %}:

jinja
<!doctype html>
<html lang="{{ page.lang|default('en', true) }}">
  <head>
    <title>{{ page.title|default(site.name, true) }}</title>
    <!--onv:head-->
  </head>
  <body>
    {% block header %}{% global_partial path="globals/header.html" %}{% endblock %}
    {% block main %}{% endblock %}
    {% block footer %}{% global_partial path="globals/footer.html" %}{% endblock %}
  </body>
</html>

The global header and footer are edited once and shown on every page; an empty {% block main %} is the content slot pages fill. A page can even override the header/footer blocks for a special landing page. If a custom layout ever errors, the site safely falls back to the default layout — a broken layout never blanks a live page.

Good to know ​

  • Mistakes are caught when you save. A template that does not compile is refused with the line and column, and the code editor marks the spot as you type.
  • A missing value renders empty instead of breaking the page — combine it with default for a fallback. Reading a name nothing declares shows a warning in the editor.
  • No JavaScript runs in templates. For interactivity, add page JS in the page's script field; the template only shapes the HTML.
  • Whitespace control: add a hyphen inside a tag ({%- ... -%}) to trim surrounding whitespace when your output spacing matters.

Ask the AI to draft it

Not sure where to start? Open the builder's AI panel and describe the section you want — it generates a coded block you can then refine by hand.