# Kida Template Engine

URL: /bengal/docs/build-sites/customize/templating/kida/
Section: kida
Description: Template engine with unified block endings, pattern matching, pipelines, and automatic caching

---

> For a complete page index, fetch /bengal/llms.txt.

Bengal's default template engine. Kida renders templates faster than Jinja2, supports free-threaded Python, and caches site-scoped blocks automatically.

Note

Do I need this? Yes when writing Kida templates or migrating from Jinja2.
For a guided tutorial, see Kida Tutorial (/bengal/docs/tutorials/theming/getting-started-with-kida/).
For exhaustive syntax, see Kida Syntax (/bengal/docs/reference/kida-syntax/).

Performance: Single-threaded, Kida is up to 3.6x faster on minimal templates. Under concurrent workloads, Kida maintains its performance advantage due to its thread-safe, GIL-independent design.

kida
KIDA

```
{% let posts = site.pages |> where('type', 'blog') |> take(5) %}

{% for post in posts %}
  <article>
    <h2>{{ post.title }}</h2>
    <time>{{ post.date | dateformat('%B %d, %Y') }}</time>
  </article>
{% end %}
```
Jinja2 compatibility: Most Jinja2 templates work without changes. Kida parses both Jinja2 syntax (`{% endif %}`, `{% endfor %}`, etc.) and Kida-native syntax (`{% end %}`, `|>`, `?.`, `??`). However, Kida does not support all Jinja2 features—notably, `{% macro %}` is not supported (use `{% def %}` instead). If you need full Jinja2 compatibility, you can use the Jinja2 engine by setting `template_engine: jinja2`in your config.

## Key Features

Feature
Benefit
Example

Unified endings
`{% end %}`for all blocks
`{% if %}...{% end %}` instead of `{% endif %}`

Pattern matching
`{% match %}...{% case %}` replaces `if/elif`chains
Cleaner branching logic

Pipeline operator
`|>`for left-to-right filter chains
`items |> filter() |> sort() |> take(5)`

Optional chaining
`?.`for safe navigation
`user?.profile?.name` returns `None`if any part is missing

Null coalescing
`??`for concise fallbacks
`page.subtitle ?? page.title`uses subtitle if available

Scope-aware functions
`{% def %}`functions access outer variables
No need to pass`site` or `config`as parameters

Automatic caching
Site-wide blocks render once per build
Navigation, footer cached automatically

## Topics

Syntax

Kida template syntax reference

(/bengal/docs/build-sites/customize/templating/kida/syntax/)

Caching

Automatic and manual template caching

(/bengal/docs/build-sites/customize/templating/kida/caching/)

Migration

Migrating to Kida from Jinja2

(/bengal/docs/build-sites/customize/templating/kida/migration/)

## Standalone Pages

Create a Custom Template

Build a custom template from scratch using Kida syntax

(/bengal/docs/build-sites/customize/templating/kida/create-custom-template/)

Kida Architecture

Compilation pipeline, AST structure, and rendering implementation

(/bengal/docs/build-sites/customize/templating/kida/architecture/)

Add a Custom Filter

Extend Kida with your own template filters

(/bengal/docs/build-sites/customize/templating/kida/add-custom-filter/)

Kida Performance

Automatic caching, free-threading, and optimization strategies

(/bengal/docs/build-sites/customize/templating/kida/performance/)

## Quick Syntax Reference

Feature
Kida
Jinja2
Notes

Block endings
`{% end %}`
`{% endif %}`, `{% endfor %}`, etc.
Unified syntax for all blocks

Template variables
`{% let x = ... %}`
`{% set x = ... %}`
Template-scoped assignment

Pattern matching
`{% match %}...{% case %}`
`{% if %}...{% elif %}`
Replaces long if/elif chains

Pipeline operator
`|>`
Not available
Left-to-right filter chains

Optional chaining
`?.`, `?[`
Not available
Safe navigation:`obj?.attr`, `obj?['key']`

Null coalescing
`??`
`| default()`
Fallback operator:`value ?? default`

Fragment caching
`{% cache key %}...{% end %}`
Extension required
Built-in caching directive

Functions
`{% def %}`(lexical scope)
`{% macro %}`(isolated)
Functions see outer variables

Range literals
`1..10`
`range(1, 11)`
Inclusive range syntax

## Learn More

- Kida Syntax Reference (/bengal/docs/reference/kida-syntax/) — Complete syntax documentation

- Operators Guide (/bengal/docs/build-sites/customize/templating/kida/syntax/operators/) — Pipeline, optional chaining, and null coalescing

- Template Functions (/bengal/docs/reference/template-functions/) — Available filters and functions

- Migrating from Jinja2 (/bengal/docs/build-sites/customize/templating/kida/migration/from-jinja/) — Step-by-step migration guide

## Kida Documentation

Kida is developed as a standalone template engine. For comprehensive documentation including API reference, extending the engine, and standalone usage:

- Getting Started with Kida (https://lbliii.github.io/kida/docs/get-started) — Installation and quickstart

- Syntax Reference (https://lbliii.github.io/kida/docs/syntax) — Complete syntax documentation

- Filters Reference (https://lbliii.github.io/kida/docs/reference/filters) — All built-in filters

- Performance (https://lbliii.github.io/kida/docs/about/performance) — Benchmarks and optimization tips

## In This Section

Syntax (/bengal/docs/build-sites/customize/templating/kida/syntax/)

Kida template syntax reference

5 pages

Caching (/bengal/docs/build-sites/customize/templating/kida/caching/)

Automatic and manual template caching

3 pages

Migration (/bengal/docs/build-sites/customize/templating/kida/migration/)

Migrating to Kida from Jinja2

2 pages

Add a Custom Filter (/bengal/docs/build-sites/customize/templating/kida/add-custom-filter/)

Extend Kida with your own template filters

Create a Custom Template (/bengal/docs/build-sites/customize/templating/kida/create-custom-template/)

Build a custom template from scratch using Kida syntax

Kida Architecture (/bengal/docs/build-sites/customize/templating/kida/architecture/)

Compilation pipeline, AST structure, and rendering implementation

Kida Performance (/bengal/docs/build-sites/customize/templating/kida/performance/)

Automatic caching, free-threading, and optimization strategies

Related Pages

Templating (/bengal/docs/build-sites/customize/templating/)

Kida template engine, layouts, inheritance, and partials

Related

Assets (/bengal/docs/build-sites/customize/assets/)

CSS, JavaScript, images, and fonts

Related

Build Sites (/bengal/docs/build-sites/)

Write, structure, customize, and extend your Bengal site

Related

Theming (/bengal/docs/build-sites/customize/)

Templates, assets, and visual customization

Related

Template Cookbook (/bengal/docs/build-sites/customize/recipes/)

Common templating patterns and Bengal-specific features

Related

persona-themer (/bengal/tags/persona-themer/)
