Twig Functions & Filters

PteroCA provides custom Twig functions and filters available in all theme templates (panel, landing, and email contexts). These are defined in the core Twig extensions and can be used in any template.

Global Functions

get_currency()

Returns the configured internal currency name (e.g., "USD", "EUR").

{{ get_currency() }}
{# Output: USD #}

Returns: string Throws: Exception if internal currency is not configured.


get_default_theme_colors()

Returns the default theme colors for light and dark mode.

{% set colors = get_default_theme_colors() %}
{{ colors['default_theme_light_mode_color'] }}
{{ colors['default_theme_dark_mode_color'] }}

Returns: array — associative array with light and dark mode color setting values.


get_app_version()

Returns the current PteroCA application version.

Returns: string


Returns the path to the site logo. If a custom logo has been uploaded in settings, returns the uploaded logo path; otherwise returns the default logo.

Returns: string — URL path (e.g., /uploads/settings/logo.png or /assets/img/logo/logo.png).


get_favicon()

Returns the path to the site favicon. If a custom favicon has been uploaded, returns the uploaded path; otherwise returns the default.

Returns: string — URL path (e.g., /uploads/settings/favicon.ico or /assets/img/favicon/favicon.ico).


get_title()

Returns the configured site title.

Returns: string


get_site_url()

Returns the configured site URL.

Returns: string


show_email_verification_alert()

Returns whether the email verification alert should be shown. True when email verification is set to "required" or "optional" in settings.

Returns: bool


get_captcha_site_key()

Returns the Google reCAPTCHA site key if captcha is enabled, or null if disabled.

Returns: string|null


use_pterodactyl_panel_as_client_panel()

Returns whether PteroCA is configured to redirect users to the Pterodactyl panel instead of using its own client area.

Returns: bool


get_pterodactyl_panel_url(path)

Returns the Pterodactyl panel URL, optionally appending a path.

Parameter
Type
Default
Description

path

string

''

Path to append to the panel URL

Returns: string


is_pterodactyl_sso_enabled()

Returns whether Pterodactyl SSO (Single Sign-On) is enabled.

Returns: bool


is_manage_in_pterodactyl_button_enabled()

Returns whether the "Manage in Pterodactyl" button should be shown on server pages.

Returns: bool


template_asset(path)

Resolves an asset path relative to the current theme's assets directory. The resulting path follows the pattern /assets/theme/{current-theme}/{path}.

Parameter
Type
Description

path

string

Relative path within the theme's assets directory

Returns: string — full public URL to the asset.


get_current_template_options()

Returns the current template's configuration options as a TemplateOptionsDTO object, parsed from the theme's template.json file.

Returns: TemplateOptionsDTO


plugin_asset(pluginName, path)

Resolves an asset path for a specific plugin's assets.

Parameter
Type
Description

pluginName

string

The plugin identifier

path

string

Relative path within the plugin's assets directory

Returns: string — full public URL to the plugin asset.


get_custom_head_scripts(context)

Returns custom head scripts configured in settings for the given context.

Parameter
Type
Default
Description

context

string

'panel'

Either 'panel' or 'landing'; any other value defaults to 'panel'

Returns: string|null


get_price_separators()

Returns the configured decimal and thousands separators for price formatting.

Returns: array — with keys decimal and thousands.

Filters

format_bytes

Converts a byte count into a human-readable string (e.g., KB, MB, GB).

Parameter
Type
Default
Description

precision

int

2

Number of decimal places


app_date

Formats a DateTimeInterface value using the application's configured date format.


format_price

Formats a numeric price value using the application's configured price format (decimal and thousands separators).

Server Permission Functions

These functions are available in server-related templates to check Pterodactyl server permissions for the current user. They operate on a ServerPermissionCollection object.

hasServerPermission(permissionCollection, permission)

Checks if the user has a specific server permission.

Parameter
Type
Description

permissionCollection

ServerPermissionCollection|null

The permission collection

permission

string

The permission to check (e.g., 'control.start')

Returns: bool


hasAllServerPermissions(permissionCollection, permissions)

Checks if the user has all of the specified permissions.

Parameter
Type
Description

permissionCollection

ServerPermissionCollection|null

The permission collection

permissions

string[]

Array of permissions to check

Returns: bool


hasAnyServerPermission(permissionCollection, permissions)

Checks if the user has any of the specified permissions.

Parameter
Type
Description

permissionCollection

ServerPermissionCollection|null

The permission collection

permissions

string[]

Array of permissions to check

Returns: bool


hasServerPermissionInCategory(permissionCollection, category)

Checks if the user has any permission within a given category.

Parameter
Type
Description

permissionCollection

ServerPermissionCollection|null

The permission collection

category

string

The permission category (e.g., 'control', 'database', 'backup')

Returns: bool


hasAllServerPermissionsInCategory(permissionCollection, category)

Checks if the user has all permissions within a given category.

Parameter
Type
Description

permissionCollection

ServerPermissionCollection|null

The permission collection

category

string

The permission category

Returns: bool

Security Filters

safe_html

Sanitizes HTML content using Symfony's HtmlSanitizer, removing potentially dangerous elements while preserving safe HTML markup.

This filter is safe for HTML output (marked with is_safe: ['html']), so the sanitized result is rendered as HTML. Use this instead of |raw when displaying user-provided HTML content.

Returns: string — sanitized HTML. Returns empty string if input is null or empty.

Last updated