FOSSBilling uses Twig across themes, email templates, and PDFs. This page lists the filters and functions you can rely on while building against it.
Standard Twig
Section titled “Standard Twig”FOSSBilling includes the default Twig filters, plus the Intl Extra Extension and Markdown Extra Extension.
Common bundled filters include:
| Filter | Description |
|---|---|
format_currency | Format a number as currency, for example {{ 29.99 | format_currency('USD') }}. |
format_date | Format a date using the configured locale and date format. |
format_datetime | Format a date and time using the configured locale and time zone. |
markdown_to_html | Convert Markdown to HTML with FOSSBilling's safe CommonMark renderer. |
FOSSBilling Custom Filters
Section titled “FOSSBilling Custom Filters”Project-specific filters and functions are defined in these classes:
FOSSBilling\Twig\Extension\ApiExtensionFOSSBilling\Twig\Extension\FOSSBillingExtensionFOSSBilling\Twig\Extension\LegacyExtensionFOSSBilling\Twig\Extension\DebugBarExtension
Translation & Localization
Section titled “Translation & Localization”| Filter | Description |
|---|---|
trans | Translate a string using FOSSBilling's translation system. |
timeago | Show how long ago a date was (e.g., "2 hours ago"). Accepts ISO 8601 format. |
daysleft | Show days until a date. Accepts ISO 8601 format. |
period_title | Display a translated period title (e.g., 1M → "1 Month"). |
ip_country_name | Show the country name for an IP address. |
URLs & Links
Section titled “URLs & Links”| Filter | Description |
|---|---|
url | Generate a URL for the current area, or pass area: 'admin' / area: 'client'. |
api_url | Generate a URL for an API endpoint. Defaults to the current area; pass role: 'admin', role: 'client', or role: 'guest' when needed. |
Assets & Resources
Section titled “Assets & Resources”| Filter | Description |
|---|---|
asset_url | Get the URL for a theme asset. |
library_url | Get the URL for the library folder. |
mod_asset_url | Get the URL for a module asset. Use the asset path as the filtered value and the module name as the argument. |
script_tag | Generate an HTML <script> tag. |
stylesheet_tag | Generate an HTML <link> tag for CSS. |
Utilities
Section titled “Utilities”| Filter | Description |
|---|---|
file_size | Convert bytes to a human-readable size (KB, MB, GB, etc.). |
hash | Hash a value. Defaults to xxh128; pass another PHP-supported algorithm if needed. |
truncate | Truncate a string to a maximum length. |
FOSSBilling Custom Functions
Section titled “FOSSBilling Custom Functions”| Function | Description |
|---|---|
fb_api | Refer to JavaScript Wrapper for documentation. |
fb_api_form | Refer to JavaScript Wrapper for documentation. |
fb_api_link | Refer to JavaScript Wrapper for documentation. |
render_widgets | Render widgets registered for a slot. |
svg_sprite | Render the current theme's SVG icon sprite when available. |
has_permission | Check whether the logged-in admin has a module permission. |
Usage Examples
Section titled “Usage Examples”{# 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.