Template Language
The template language is used in code generation to produce output strings from a mix of literal text and dynamic variable expressions.
Syntax
Plain text
Any text that is not a variable expression is output verbatim.
Hello, world!Variables
A variable is written as ${name}. It is replaced with the value bound to name at render time. If no value is bound the expression is left unchanged in the output.
Hello, ${userName}!Variable names may contain letters (a–z, A–Z), digits (0–9), and underscores (_).
Mutators (transformations)
One or more mutators can be chained after the variable name, separated by |.
${varName|mutator1|mutator2}Mutators are applied left-to-right. Some mutators accept a single argument provided after :.
${varName|mutatorName:argument}To include a literal | inside an argument, escape it with a backslash: \|.
System Variables
These variables are provided automatically and do not need to be passed in.
| Variable | Value |
|---|---|
CURRENT_TIME | Current UTC date-time in yyyy-MM-dd HH:mm:ss |
Mutator Reference
String case
| Mutator | Description |
|---|---|
upperCase | Converts every character to upper case |
lowerCase | Converts every character to lower case |
snakeCase | Converts camelCase to snake_case |
kebabCase | Converts camelCase to kebab-case |
upperCamelCase | Converts snake_case to UpperCamelCase |
lowerCamelCase | Converts snake_case to lowerCamelCase |
Whitespace and characters
| Mutator | Argument | Description |
|---|---|---|
trim | (optional) | Trims whitespace from both ends; if an argument is given, trims those characters instead |
trimStart | (optional) | Same as trim, but from the start only |
trimEnd | (optional) | Same as trim, but from the end only |
Replacement
| Mutator | Argument | Description |
|---|---|---|
replace | old,new | Replaces all occurrences of old with new |
convertToClassName | (optional) | Replaces every non-word character with _ (or the supplied character) and strips leading spaces/underscores |
Plural / singular
| Mutator | Description |
|---|---|
singular | Returns the singular form of a word |
plural | Returns the plural form of a word |
PHP FQN helpers
| Mutator | Description |
|---|---|
className | Extracts the class name from a fully-qualified name (last segment) |
namespace | Extracts the namespace from a fully-qualified name (everything before the last \) |
namespaceString | Produces a namespace Foo\Bar; declaration (with surrounding newlines), or an empty string for root/empty FQNs |
useClassString | Produces a use Foo\Bar\Class; statement, or an empty string for an empty FQN |
Date formatting
| Mutator | Argument | Description |
|---|---|---|
format | pattern | Re-formats a date string (input must be in yyyy-MM-dd HH:mm:ss); uses Java SimpleDateFormat pattern syntax |
Examples
Basic variable substitution
Template : Hello, ${name}!
Variables: name = "World"
Output : Hello, World!Case transformations
Template : ${model|upperCase}
Variables: model = "userProfile"
Output : USERPROFILE
Template : ${model|lowerCase}
Variables: model = "UserProfile"
Output : userprofile
Template : ${model|snakeCase}
Variables: model = "UserProfile"
Output : user_profile
Template : ${model|kebabCase}
Variables: model = "UserProfile"
Output : user-profile
Template : ${model|upperCamelCase}
Variables: model = "user_profile"
Output : UserProfile
Template : ${model|lowerCamelCase}
Variables: model = "user_profile"
Output : userProfileChaining mutators
Mutators are applied in order from left to right.
Template : ${model|snakeCase|upperCase}
Variables: model = "UserProfile"
Output : USER_PROFILE
Template : ${model|plural|upperCamelCase}
Variables: model = "user_post"
Output : UserPostsPlural / singular
Template : ${table|singular}
Variables: table = "some_posts"
Output : some_post
Template : ${table|plural}
Variables: table = "some_post"
Output : some_postsTrim
Template : [${value|trim}]
Variables: value = " hello "
Output : [hello]
Template : [${value|trim:|}]
Variables: value = "||hello||"
Output : [hello]
Template : [${value|trim:\|}]
Variables: value = "||hello||"
Output : [hello]
(the \| escapes the pipe so it is treated as the character to trim, not a mutator separator)Replace
Template : ${value|replace:foo,bar}
Variables: value = "foo baz foo"
Output : bar baz barConvert to class name
Template : ${value|convertToClassName}
Variables: value = "some posts"
Output : some_posts
Template : ${value|convertToClassName}
Variables: value = "some%posts"
Output : some_postsFQN helpers
Template : ${fqn|className}
Variables: fqn = "\App\Http\Controllers\UserController"
Output : UserController
Template : ${fqn|namespace}
Variables: fqn = "\App\Http\Controllers\UserController"
Output : App\Http\Controllers
Template : ${fqn|namespaceString}
Variables: fqn = "\App\Http\Controllers\UserController"
Output :
namespace App\Http\Controllers;
Template : ${fqn|useClassString}
Variables: fqn = "\App\Http\Controllers\UserController"
Output : use App\Http\Controllers\UserController;
Template : ${fqn|namespaceString}
Variables: fqn = "RootClass"
Output : (empty string — no namespace for a root-level class)Date formatting
Template : ${CURRENT_TIME|format:dd.MM.yyyy}
Output : 23.05.2026 (today's UTC date)
Template : ${CURRENT_TIME|format:HH:mm}
Output : 14:30 (current UTC hour and minute)Realistic code-generation template
Template:
${fqn|namespaceString}
class ${fqn|className} extends Model
{
protected $table = '${fqn|className|snakeCase|plural}';
}
Variables: fqn = "\App\Models\UserPost", name = "user_post"
Output:
namespace App\Models;
class UserPost extends Model
{
protected $table = 'user_posts';
}Notes
- If a variable name is not found in the provided variables and is not a system variable, the original
${...}expression is preserved in the output. - Variable names are case-sensitive.
- Unknown mutator names are silently ignored; the value passes through unchanged.
- The
formatmutator expects its input to be inyyyy-MM-dd HH:mm:ss(UTC). Pair it withCURRENT_TIMEor another variable that stores dates in that format.