Handlebars Template Functions

The full reference for every custom Handlebars helper available when writing or editing Waddle project config templates.

Every config file in a Waddle project is rendered from a Handlebars template at build time, including any custom template you add yourself. This page documents the custom helpers available to those templates. For the data every template has access to, see Template Data.

Path helpers

project_path

Generates an absolute guest path inside the container by prefixing the project root. Rejects empty, absolute, or ..-containing paths.

{{project_path 'php/conf'}}

Output: /etc/waddle/project/php/conf

Use project_path only for values interpreted inside a container: arguments to docker compose exec, paths inside shell heredocs piped to exec, or templates rendered inside a container (e.g. Nginx config, PHP-FPM pool config). Scripts that run on the host directly should use relative paths instead.

container

Builds a container’s fully qualified name from a service name and a domain, for containers that need to address each other.

{{container 'php' 'example'}}

Output: php_example.example_example

Both arguments are required; empty values raise a render error.

Package management

install

Generates the package install command for the guest distro. First argument is a provider’s docker config, second is an array of package names.

{{install public.php.docker packages.php.compiletime}}

Output:

  • Alpine: apk add --no-cache package1 package2
  • Debian: apt-get install -y package1 package2
  • Debian 7 and 8: apt-get install -y --force-yes package1 package2, since their archived repositories’ signing keys have expired

update_repo

Generates the package-repository update command for the guest distro.

{{update_repo public.php.docker}}

Output:

  • Alpine: apk update --no-cache
  • Debian: apt-get update -y

get_additional_repos

Emits the commands needed to add archived package repositories for end-of-life distro versions. Returns an empty string for currently-supported versions. Conventionally prefixed directly onto update_repo so it runs first:

{{get_additional_repos public.php.docker}}{{update_repo public.php.docker}}

Utility string helpers

coalesce

Returns the first non-null, non-empty string argument. Useful for fallback values without a verbose {{#if}} chain.

{{coalesce public.mail.from_email public.website.admin_email}}

If public.mail.from_email is null or empty, this renders public.website.admin_email instead.

Conditionals

not_empty

Checks if a value is not empty. Works on strings and arrays (including arrays of objects, such as php_extensions.pecl); null counts as empty.

{{#if (not_empty php_extensions.packages.compiletime)}}
{{install public.php.docker php_extensions.packages.compiletime}}
{{/if}}

It also works as a block helper, as in {{#not_empty value}}...{{else}}...{{/not_empty}}.

is_equal

Compares two values for strict equality, meaning same type and same value, case-sensitive. The number 8080 doesn’t equal the string "8080", and a distro is "Debian", not "debian".

{{#if (is_equal public.website.platform "wordpress")}}
{{! WordPress specific config }}
{{/if}}

some

Returns true if any argument is a boolean true, or a non-empty string. Anything else, including numbers and arrays, counts as false.

{{#if (some public.php.install public.nginx.install)}}
{{! At least one is enabled }}
{{/if}}

includes

Checks if an array of strings contains a value.

{{#if (includes 'git' packages.php.runtime)}}
{{! git is installed in the PHP container }}
{{/if}}

Only works on arrays of strings. public.php.extensions, for example, is an array of Extension objects and raises a render error.

gt

Greater-than comparison between two numbers, decimals included. Both arguments must be numbers, and a string such as "4" raises a render error.

{{#if (gt public.php.ram 512)}}
{{! More than 512 MB for PHP }}
{{/if}}

version_compare

Compares software versions. Operators: <, <=, >, >=, ==, !=. Note it’s == for equality, not =; a stray single = won’t error, it silently evaluates to false.

{{#if (version_compare tags.php.version.raw '>=' '8.1.0')}}
{{! PHP 8.1+ specific }}
{{/if}}

Build helpers

integrity_hash

Generates a hash of a rendered project file’s contents, for Docker image tagging. When the file changes, so does the tag, and the image is rebuilt. Takes the file’s path relative to the project root, and project_dirname. Waddle renders the referenced file first, so the hash always reflects its current contents.

image: {{integrity_hash 'php/Dockerfile' project_dirname}}

Output: image: a1b2c3d4e5f6...

parse_compile_options

Outputs the resolved compile options for a software build. Takes the software (php, nginx or mariadb), the resolved version, and the configured CompileOption list; each option id is mapped to the build flag that version actually uses.

{{parse_compile_options 'php' tags.php.version.raw public.php.compile_options}}

Output: --enable-opcache --with-openssl ...

has_compile_option

Checks if a compile option is enabled. An optional third argument also requires the option’s argument to match it (case-insensitively).

{{#if (has_compile_option 'pear' public.php.compile_options)}}
{{! PEAR is enabled }}
{{/if}}

{{#if (has_compile_option 'PLUGIN_DUCKDB' public.mariadb.compile_options 'NO')}}
{{! The DuckDB plugin is explicitly turned off }}
{{/if}}

PHP extension helpers

PHP extensions are resolved at render time into php_extensions.pecl and php_extensions.pie (each a list of extension objects).

get_pecl_extension

Formats a PECL extension object as id (or id-version when a version is explicitly specified).

{{#each php_extensions.pecl}}
pecl install -o "{{get_pecl_extension this}}"
{{/each}}

get_pie_extension

Formats a PIE extension object as package (or package:version when a version is explicitly specified).

{{#each php_extensions.pie}}
pie install "{{get_pie_extension this}}"
{{/each}}

Daemon identity helpers

Resolve the unprivileged user/group a service should drop to, per guest distro.

get_daemon_user

user = {{get_daemon_user public.php.docker}}

Output: nobody

get_daemon_group

group = {{get_daemon_group public.php.docker}}

Output:

  • Alpine: nobody
  • Debian: nogroup

Platform helpers

Platform specific helper functions.

get_platform_runtime

The runtime a platform’s website runs on, as the name of its Docker Compose service, either php or node. Returns php for an unknown platform.

{{#if (is_equal (get_platform_runtime public.website.platform) 'node')}}
{{! Proxy to the node service instead of PHP-FPM }}
{{/if}}

get_platform_node_command

The shell command line for a task on a Node platform’s website. The second argument is the task: development, build or production. An unknown task raises a render error.

Each task defaults to the most common npm script, which platforms with differently named scripts override. An unknown platform also gets these defaults:

Task Default
development exec npm run dev
build npm run build
production exec npm run start
command: 'sh -c "{{get_platform_node_command public.website.platform 'production'}}"'

Output for Strapi: exec npm run start

get_daemon_owned_dirs

The platform’s directories, relative to website/src/, that the unprivileged daemon user needs to own at runtime, such as caches, sessions, logs and uploads. Returns an empty list for most platforms.

{{#each (get_daemon_owned_dirs public.website.platform)}}website/src/{{this}}/
{{/each}}

Output for Drupal: website/src/web/sites/default/files/

The platform’s command-line entry points, as objects with a name and a target, e.g. Laravel’s artisan. Returns an empty list for platforms without one.

{{#each (get_bin_links public.website.platform)}}bin/{{this.name}}
{{/each}}

get_deploy_files

The platform’s secret-bearing config files, relative to the project root, e.g. website/src/wp-config.php for WordPress or website/src/.env for Laravel. Returns an empty list for platforms without any.

{{#each (get_deploy_files public.website.platform)}}{{this}}
{{/each}}

Other utility helpers

random_str

Generates a random alphanumeric string of the given length. The length must be at least 1; decimals are truncated.

SECRET_KEY={{random_str 32}}

join

Joins an array of strings with a separator.

{{join verifications.php.gpg_keys ' '}}

Output: key1 key2 key3

Common patterns

Conditionally include a whole service:

{{#if public.redis.install}}
redis:
  image: {{integrity_hash 'redis/Dockerfile' project_dirname}}
{{/if}}

Version-specific logic:

{{#if (version_compare tags.php.version.raw '<' '5.5.0')}}
PHP_TAR_EXT="gz"
{{else}}
PHP_TAR_EXT="xz"
{{/if}}

Platform-specific config:

{{#if (is_equal public.website.platform "magento")}}
include {{project_path 'nginx/conf'}}/magento.conf;
{{/if}}