Skip to content

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.

VariableValue
CURRENT_TIMECurrent UTC date-time in yyyy-MM-dd HH:mm:ss

Mutator Reference

String case

MutatorDescription
upperCaseConverts every character to upper case
lowerCaseConverts every character to lower case
snakeCaseConverts camelCase to snake_case
kebabCaseConverts camelCase to kebab-case
upperCamelCaseConverts snake_case to UpperCamelCase
lowerCamelCaseConverts snake_case to lowerCamelCase

Whitespace and characters

MutatorArgumentDescription
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

MutatorArgumentDescription
replaceold,newReplaces 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

MutatorDescription
singularReturns the singular form of a word
pluralReturns the plural form of a word

PHP FQN helpers

MutatorDescription
classNameExtracts the class name from a fully-qualified name (last segment)
namespaceExtracts the namespace from a fully-qualified name (everything before the last \)
namespaceStringProduces a namespace Foo\Bar; declaration (with surrounding newlines), or an empty string for root/empty FQNs
useClassStringProduces a use Foo\Bar\Class; statement, or an empty string for an empty FQN

Date formatting

MutatorArgumentDescription
formatpatternRe-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   : userProfile

Chaining 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   : UserPosts

Plural / singular

Template : ${table|singular}
Variables: table = "some_posts"
Output   : some_post

Template : ${table|plural}
Variables: table = "some_post"
Output   : some_posts

Trim

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 bar

Convert to class name

Template : ${value|convertToClassName}
Variables: value = "some posts"
Output   : some_posts

Template : ${value|convertToClassName}
Variables: value = "some%posts"
Output   : some_posts

FQN 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 format mutator expects its input to be in yyyy-MM-dd HH:mm:ss (UTC). Pair it with CURRENT_TIME or another variable that stores dates in that format.