Template Functions

Quick overview of filters and functions available in templates

1 min read 248 words

Bengal provides 80+ template functions and filters organized by category.

Functions vs Filters

Bengal provides filters (transform values) and functions (standalone operations).

Filters use the pipe operator:

{{ text | upper }}
{{ pages |> where('draft', false) |> sort_by('date') }}

Functions are called directly:

{{ get_page('docs/about') }}
{{ get_data('data/config.json') }}
{{ ref('docs/getting-started') }}

Tip

Quick rule: Transform a value? Use a filter (|). Perform an operation? Use a function (direct call).

See Template Functions Reference for complete explanation.

Function Categories

Category Examples Use For
Collection where, sort_by, group_by, limit Querying and filtering pages
Navigation get_section, get_breadcrumbs, get_nav_tree Building navigation
Linking ref, doc, anchor, relref Cross-references
Text truncatewords, slugify, markdownify Text transformations
Date time_ago, days_ago, date_iso Date formatting
i18n t, current_lang, locale_date Internationalization

Quick Examples

Filter Pages

{% let posts = site.pages
  |> where('type', 'blog')
  |> where('draft', false)
  |> sort_by('date', reverse=true)
  |> limit(10) %}

Build Navigation

{% let docs = get_section('docs') %}
{% let crumbs = get_breadcrumbs(page) %}

Cross-Reference

{{ ref('docs/getting-started') }}
{{ ref('docs/api', 'API Reference') }}

Seealso