Skip to content

Search tags, filters, functions and guides.

Guides / Coming from Twig

Guides

Coming from Twig

What is the same, what changed and why.

Kiln's syntax is close to Twig's, so most templates read the same. The differences fix things that tend to cause bugs, follow JavaScript where Twig follows PHP, or remove features a website doesn't need.

Renamed

TwigKiln
embedcomponent with slot and fill
typesprops, which also checks values and sets defaults
json_encodejson
number_formatformatNumber, with Intl options
date filterformatDate, with Intl options instead of formats like "Y-m-d"
striptags, url_encodestripTags, urlEncode
loop.revindexloop.revIndex
escape("html_attr")escape("attr")
_self.macro()macro()

All of Kiln's names are camelCase, like JavaScript.

Changed

AreaTwigKiln
Missing variablesEmpty, unless strict_variables is onAn error, unless you turn off strict mode
include and componentsShare the caller's variables unless you add onlyOnly see what you pass, plus globals
ImportsHidden in some places, such as inside an embedWork everywhere in the template that declares them
==Loose, with PHP's rulesStrict, like ===
True and false"0" is false"0" is true. Empty arrays and hashes are false
Printing booleans1 and nothingtrue and false
+Converts numeric stringsNumbers only
in on a hashChecks valuesChecks keys
~Runs before +Runs after +
Named argumentsMatched to parameter namesGathered into one hash at the end, except for macros
Property accessattribute() for dynamic namesobj[name] works everywhere
Method callsAny public methodOnly methods a class exposes
TimestampsSecondsMilliseconds, like JavaScript
sliceStart and lengthStart and end, like JavaScript
WhitespaceRemoves the first newline after a tagRemoves lines that only hold tags, and the extra indentation inside tags. Indents inserted content to line up with its tag
AsyncNot supportedAny call can return a promise
flushSends the output so farCloses the outlets above it, so a streamed page can be sent up to it

Removed

  • Tags: sandbox, use, deprecated, do and guard. Kiln's safety model replaces the sandbox.
  • Functions: include(), attribute, constant, source, template_from_string and random. Use the include tag and [] instead of the first two.
  • Filters: spaceless, convert_encoding, format, date_modify and the e alias. Use - to trim whitespace, and #{ } to build strings.
  • Tests: same as, constant and none. == is already strict, and null replaces none.
  • Syntax: the matches operator, bitwise operators, items[1:3] slices, letter ranges such as 'a'..'z', loop.parent, the only keyword, upper-case TRUE, FALSE and NULL, and custom delimiters.