# Template Functions Reference

URL: /bengal/docs/0.5.1/reference/template-functions/
Section: template-functions
Description: Complete reference for Bengal's template filters and functions

---

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

Bengal provides powerful template filters for querying, filtering, and transforming content collections. Many filters are inspired by Hugo for easy migration.

Important

Implementation Maturity: Bengal currently ships with over 80+ native template functions and filters. While our documentation is being expanded to provide exhaustive examples for every edge case, the core implementation for Math, Strings, Collections, SEO, and Autodoc is fully production-ready and registered in the engine.

## Functions vs Filters: Understanding the Difference

Bengal provides two types of template capabilities: functions and filters. Understanding when to use each helps you write clearer, more efficient templates.

### Filters: Transform Values

Filters transform a value using the pipe operator (`|` or `|>`). The value on the left becomes the first argument to the filter.

Syntax:

kida
KIDA

```
{{ value | filter }}
{{ value | filter(arg1, arg2) }}
{{ value |> filter1 |> filter2 }}
```
When to use: When you have a value to transform.

Examples:

kida
KIDA

```
{# Transform text #}
{{ page.title | upper }}
{{ page.content | markdown | safe }}

{# Transform collections #}
{{ site.pages | where('draft', false) | sort_by('date') }}

{# Chain transformations #}
{{ text |> slugify |> truncate(50) }}
```
Registered in: `env.filters`(available via pipe operator)

### Functions: Standalone Operations

Functions are called directly without a value to transform. They perform operations or retrieve data.

Syntax:

kida
KIDA

```
{{ function() }}
{{ function(arg1, arg2) }}
```
When to use: When performing an operation that doesn't transform an existing value.

Examples:

kida
KIDA

```
{# Retrieve data #}
{{ get_page('docs/about') }}
{{ get_data('data/authors.json') }}

{# Generate references #}
{{ ref('docs/getting-started') }}
{{ get_section('blog') }}

{# Check conditions #}
{{ page_exists('path/to/page') }}
```
Registered in: `env.globals`(available as direct function calls)

### Quick Decision Guide

Use Case
Type
Example

Transform text
Filter
`{{ text \| upper }}`

Transform a collection
Filter
`{{ pages \| where('draft', false) }}`

Chain transformations
Filter
`{{ data \|> filter1 \|> filter2 }}`

Retrieve a page
Function
`{{ get_page('path') }}`

Load data file
Function
`{{ get_data('file.json') }}`

Generate cross-reference
Function
`{{ ref('docs/page') }}`

Check if page exists
Function
`{{ page_exists('path') }}`

### Why This Matters

Filters are designed for data transformation pipelines:

- Read left-to-right:`data |> transform |> format |> output`

- Chain multiple operations:`pages |> filter |> sort |> limit`

- Functional programming style

Functions are designed for operations and lookups:

- No implicit left operand

- Direct calls:`get_page('path')` not `| get_page('path')`

- Procedural style

### Common Patterns

Pattern 1: Filter a collection, then use a function

kida
KIDA

```
{% let blog_posts = site.pages |> where('type', 'blog') |> sort_by('date', reverse=true) %}
{% for post in blog_posts %}
  {# Use function to get related page #}
  {% let related = get_page(post.metadata.related) %}
  {% if related %}
    <a href="{{ related.url }}">Related: {{ related.title }}</a>
  {% end %}
{% end %}
```
Pattern 2: Function to get data, filter to transform

kida
KIDA

```
{% let authors = get_data('data/authors.json') %}
{% let active_authors = authors |> where('active', true) |> sort_by('name') %}
```
Pattern 3: Function result used in filter chain

kida
KIDA

```
{% let section = get_section('blog') %}
{% let recent = section.pages |> sort_by('date', reverse=true) |> limit(5) %}
```

Note

Can't remember which is which? Ask: "Do I have a value to transform?"

- Yes → Use a filter (`|` or `|>`)

- No → Use a function (direct call)

## Topics

Collection Filters

Filter, sort, group, and transform collections of pages or items

(/bengal/docs/0.5.1/reference/template-functions/collection-filters/)

Navigation Functions

Functions for navigating sections and checking page existence

(/bengal/docs/0.5.1/reference/template-functions/navigation-functions/)

Linking Functions

Generate links to pages, headings, and external documentation

(/bengal/docs/0.5.1/reference/template-functions/linking-functions/)

Internationalization Functions

Translation, language detection, and localized formatting

(/bengal/docs/0.5.1/reference/template-functions/i18n-functions/)

Template Functions Reference (Generated)

Auto-generated index of all template filters and functions

(/bengal/docs/0.5.1/reference/template-functions/reference-generated/)

String & Date Filters

Text transformation and date calculation filters

(/bengal/docs/0.5.1/reference/template-functions/string-date-filters/)

Page & Section Properties

Properties available on page and section objects

(/bengal/docs/0.5.1/reference/template-functions/page-properties/)

Math & Data Functions

Mathematical operations and data file manipulation

(/bengal/docs/0.5.1/reference/template-functions/math-data-filters/)

Content Filters

HTML and content manipulation filters

(/bengal/docs/0.5.1/reference/template-functions/content-filters/)

View Filters

Convert pages to normalized view objects for easier templating

(/bengal/docs/0.5.1/reference/template-functions/view-filters/)

SEO, Image & Theme Functions

SEO meta tags, image manipulation, icons, and theme features

(/bengal/docs/0.5.1/reference/template-functions/seo-image-functions/)

Debug Filters

Development helpers for debugging templates

(/bengal/docs/0.5.1/reference/template-functions/debug-filters/)

## In This Section

Collection Filters (/bengal/docs/0.5.1/reference/template-functions/collection-filters/)

Filter, sort, group, and transform collections of pages or items

Content Filters (/bengal/docs/0.5.1/reference/template-functions/content-filters/)

HTML and content manipulation filters

Debug Filters (/bengal/docs/0.5.1/reference/template-functions/debug-filters/)

Development helpers for debugging templates

Internationalization Functions (/bengal/docs/0.5.1/reference/template-functions/i18n-functions/)

Translation, language detection, and localized formatting

Linking Functions (/bengal/docs/0.5.1/reference/template-functions/linking-functions/)

Generate links to pages, headings, and external documentation

Math & Data Functions (/bengal/docs/0.5.1/reference/template-functions/math-data-filters/)

Mathematical operations and data file manipulation

Navigation Functions (/bengal/docs/0.5.1/reference/template-functions/navigation-functions/)

Functions for navigating sections and checking page existence

Page & Section Properties (/bengal/docs/0.5.1/reference/template-functions/page-properties/)

Properties available on page and section objects

SEO, Image & Theme Functions (/bengal/docs/0.5.1/reference/template-functions/seo-image-functions/)

SEO meta tags, image manipulation, icons, and theme features

String & Date Filters (/bengal/docs/0.5.1/reference/template-functions/string-date-filters/)

Text transformation and date calculation filters

Template Functions Reference (Generated) (/bengal/docs/0.5.1/reference/template-functions/reference-generated/)

Auto-generated index of all template filters and functions

View Filters (/bengal/docs/0.5.1/reference/template-functions/view-filters/)

Convert pages to normalized view objects for easier templating

Related Pages

Rendering Pipeline (/bengal/docs/0.5.1/reference/architecture/rendering/rendering/)

How Bengal transforms Markdown to HTML

Related

Theme Variables (/bengal/docs/0.5.1/reference/theme-variables/)

Comprehensive reference of all variables and functions available in Kida templates.

Related

Add a Custom Filter (/bengal/docs/0.5.1/theming/templating/kida/add-custom-filter/)

Extend Kida with your own template filters

Related

Functions vs Filters Quick Reference (/bengal/docs/0.5.1/theming/templating/functions-quick-reference/)

One-page guide to when to use functions vs filters

Related

Kida Syntax Reference (/bengal/docs/0.5.1/reference/kida-syntax/)

Complete reference for Kida template syntax, operators, and features

Related

reference (/bengal/tags/reference/)

templates (/bengal/tags/templates/)

filters (/bengal/tags/filters/)

kida (/bengal/tags/kida/)

hugo (/bengal/tags/hugo/)
