Skip to content

Twig Filters & Functions

FOSSBilling uses Twig across themes, email templates, and PDFs. This page lists the project-specific filters and functions you can rely on while building against it.

FOSSBilling includes all default Twig filters, plus the Intl Extra Extension for internationalization.

These filters are defined in /library/Box/TwigExtensions.php:

FilterDescription
transTranslate a string using FOSSBilling's translation system.
timeagoShow how long ago a date was (e.g., "2 hours ago"). Accepts ISO 8601 format.
daysleftShow days until a date. Accepts ISO 8601 format.
period_titleDisplay a translated period title (e.g., 1M → "1 Month").
FilterDescription
alinkCreate a link to the admin panel from a URI.
linkGenerate a full URL from a URI.
autolinkAutomatically convert text to HTML links.
iplookupCreate a clickable admin panel link to look up an IP address.
FilterDescription
mod_asset_urlGet the correct URL for a module asset.
asset_urlGet the URL for a theme asset.
library_urlGet the URL for the library folder.
img_tagGenerate an HTML <img> tag.
script_tagGenerate an HTML <script> tag.
stylesheet_tagGenerate an HTML <link> tag for CSS.
FilterDescription
moneyFormat a price with currency symbol.
money_without_currencyFormat a price without the currency symbol.
money_convertConvert and format a price to another currency.
money_convert_without_currencyConvert without showing the currency symbol.
numberPHP number_format() as a filter.
sizeConvert bytes to human-readable size (KB, MB, GB, etc.).
truncateTruncate a string to a maximum length.
FilterDescription
gravatarGenerate a Gravatar image URL from an email. Optional size parameter.
markdownParse Markdown to HTML. Escapes HTML and removes unsafe links (javascript:, vbscript:, file:, data:). Uses CommonMark with GitHub extensions.
ipcountrynameShow the country name for an IP address.
{# Format money #}
{{ 29.99 | money }} {# $29.99 #}
{# Generate Gravatar #}
<img src="{{ 'user@example.com' | gravatar(64) }}" alt="Avatar">
{# Parse Markdown #}
{{ product.description | markdown }}
{# Time ago #}
{{ order.created_at | timeago }} {# 2 hours ago #}
{# Admin link #}
<a href="{{ 'client/manage' | alink }}">Manage Client</a>
{# Module asset #}
<script src="{{ 'myfile.js' | mod_asset_url }}"></script>