Skip to content

Twig Filters & Functions

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

FOSSBilling includes the default Twig filters, plus the Intl Extra Extension and Markdown Extra Extension.

Common bundled filters include:

FilterDescription
format_currencyFormat a number as currency, for example {{ 29.99 | format_currency('USD') }}.
format_dateFormat a date using the configured locale and date format.
format_datetimeFormat a date and time using the configured locale and time zone.
markdown_to_htmlConvert Markdown to HTML with FOSSBilling's safe CommonMark renderer.

Project-specific filters and functions are defined in these classes:

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").
ip_country_nameShow the country name for an IP address.
FilterDescription
urlGenerate a URL for the current area, or pass area: 'admin' / area: 'client'.
api_urlGenerate a URL for an API endpoint. Defaults to the current area; pass role: 'admin', role: 'client', or role: 'guest' when needed.
FilterDescription
asset_urlGet the URL for a theme asset.
library_urlGet the URL for the library folder.
mod_asset_urlGet the URL for a module asset. Use the asset path as the filtered value and the module name as the argument.
script_tagGenerate an HTML <script> tag.
stylesheet_tagGenerate an HTML <link> tag for CSS.
FilterDescription
file_sizeConvert bytes to a human-readable size (KB, MB, GB, etc.).
hashHash a value. Defaults to xxh128; pass another PHP-supported algorithm if needed.
truncateTruncate a string to a maximum length.
FunctionDescription
fb_apiRefer to JavaScript Wrapper for documentation.
fb_api_formRefer to JavaScript Wrapper for documentation.
fb_api_linkRefer to JavaScript Wrapper for documentation.
render_widgetsRender widgets registered for a slot.
svg_spriteRender the current theme's SVG icon sprite when available.
has_permissionCheck whether the logged-in admin has a module permission.
{# Format currency #}
{{ 29.99 | format_currency('USD') }} {# $29.99 #}
{# Generate client and admin URLs #}
<a href="{{ 'invoice' | url }}">Invoices</a>
<a href="{{ 'client/manage' | url(area: 'admin') }}">Manage Client</a>
{# Generate API URLs #}
{{ 'profile/update' | api_url }}
{{ 'client/login' | api_url(role: 'guest') }}
{# Parse Markdown #}
{{ product.description | markdown_to_html }}
{# Time ago #}
{{ order.created_at | timeago }} {# 2 hours ago #}
{# Theme and module assets #}
<link rel="stylesheet" href="{{ 'css/theme.css'|asset_url }}">
<script src="{{ 'js/widget.js'|mod_asset_url('Example') }}"></script>
{# API form handled by Api/API.js #}
<form action="{{ 'profile/update'|api_url }}" {{ fb_api_form({ message: 'Saved'|trans }) }}>
<input type="text" name="first_name">
<button type="submit">{{ 'Save'|trans }}</button>
</form>
{# API link with a confirmation modal #}
<a href="{{ 'client/delete'|api_url(query: { id: client.id }, role: 'admin') }}"
{{ fb_api_link({ modal: { type: 'confirm', title: 'Are you sure?'|trans }, reload: true }) }}>
{{ 'Delete'|trans }}
</a>

See JavaScript API Wrapper for the data-fb-api options and CSRF behavior.