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 words to snake_case
upperSnakeCaseConverts words to UPPER_SNAKE_CASE: UserAccount → USER_ACCOUNT
kebabCaseConverts words to kebab-case
dotCaseConverts words to dot-separated form: UserAccount → user.account
wordsCaseConverts words to lowercase, separated by spaces: UserAccount → user account
titleCaseCapitalizes each word: user_account → User Account
sentenceCaseCapitalizes the first word: UserAccount → User account
upperCamelCaseConverts words to UpperCamelCase
lowerCamelCaseConverts words to lowerCamelCase
upperFirstUppercases the first character: userAccount → UserAccount
lowerFirstLowercases the first character: UserAccount → userAccount

Word-based case conversions recognize camel case, acronyms, spaces, underscores, hyphens, and dots. For example, snakeCase converts HTTPRequest to http_request and FooBar_test-foo to foo_bar_test_foo; upperCamelCase converts FooBar_test-foo to FooBarTestFoo, and titleCase converts UserAPIKey to User API Key.

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
removePrefixprefixRemoves the specified prefix: UserController with removePrefix:User → Controller
removeSuffixsuffixRemoves the specified suffix: UserController with removeSuffix:Controller → User
convertToClassName(optional)Replaces every non-word character with _ (or the supplied character) and strips leading spaces/underscores

Plural / singular ​

MutatorDescription
singularConverts the last word to its singular form
pluralConverts the last word to its plural form

plural and singular transform the last word of compound names while preserving surrounding text and capitalization, including irregular forms: UserPerson → UserPeople, user_child → user_children, and USER_ACCOUNTS → USER_ACCOUNT.

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

Template : ${MODEL|className|plural|titleCase}
Variables: MODEL = "\App\Models\UserAccount"
Output   : User Accounts

Plural / singular ​

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

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

# Laravel table name from model convention also works
Template : ${model|snakeCase|plural}
Variables: model = "AccountPerson"
Output   : account_people

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"

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.