Latte Filters

Verze:

05. 01. 2026

Zodpovědná osoba:

Dominik Šlechta

Built-in Latte filters SHOULD be used for formatting. Filters MAY be chained. Complex formatting logic SHOULD be moved to custom filters.

Common Filters

  • Rule: Built-in Latte filters SHOULD be used for formatting instead of PHP functions in templates.

  • Reason: Filters keep templates clean and readable, separating presentation logic from business logic.

Commonly Used Filters:

<!-- Number formatting -->
{$price|number:2:'.':','} Kč

<!-- Date formatting -->
{$createdAt|date:'j. n. Y'}
{$createdAt|date:'H:i'}

<!-- String manipulation -->
{$text|truncate:100}
{$text|upper}
{$text|lower}
{$text|capitalize}
{$text|webalize}

<!-- HTML/Text -->
{$html|striptags}
{$text|nl2br}

<!-- Arrays/Counting -->
{$items|length}
{$items|first}
{$items|last}

Filter Chaining

  • Rule: Filters MAY be chained for complex formatting.

Example:

{$description|striptags|truncate:150|capitalize}

Custom Filters

  • Rule: Complex formatting logic SHOULD be moved to custom filters registered in the presenter or configuration.

Example:

<!-- Using custom filter -->
{$product->price|formatPrice}
{$order->status|statusLabel}

Summary:

  • Built-in filters SHOULD be used for formatting.
  • Filters MAY be chained for complex formatting.
  • Complex logic SHOULD be moved to custom filters.