You can apply more options by running LightnCandy::compile($template, $options)
.
$phpStr = LightnCandy::compile($template, array(
'flags' => LightnCandy::FLAG_ERROR_LOG | LightnCandy::FLAG_STANDALONEPHP, // Compile Flags
'helpers' => array( // list of custom helpers
'custom_helper_name' => function () { .... }
),
'partials' => array( // list of partials
'partial_name' => 'partial {{foo}} template',
),
'helperresolver' => function ($context, $name) { .... }, // callback to load missing helper with name
'partialresolver' => function ($context, $name) { .... }, // callback to load missing partial with name
'prepartial' => function ($context, $template, $name) { .... }, // callback to preprocess partials
'delimiters' => array('<%', '%>'), // change default delimiters
'renderex' => '// Compiled at ' . date('Y-m-d h:i:s'), // insert the PHP code into generated render()
'runtime' => 'MyNameSpace\\MyCustomRuntime', // customized Runtime class
));
{{foo.[0].[#te#st].bar}}
or {{"some string"}}
or {{helper (subexpression ...)}}
handlebars style extensions.
FLAG_ECHO
+ FLAG_STANDALONEPHP
now. This flag may be changed base on performance testing result in the future.echo 'a', $b, 'c';
to improve performance. This will slow down rendering when the template and data are simple, but will improve 5% ~ 10% when the data is big and looping in the template.
{{else}}
or {{^}}
as handlebars specification. Otherwise, {{else}}
will be resolved as normal variable, and {{^}} will cause template error.undefined function
runtime error will be triggered.
{{foo}}
escaping logic with handlebars.js. This causes '
, =
and `
be escaped in different way.FLAG_PROPERTY
+ FLAG_METHOD
FLAG_JSTRUE
+ FLAG_JSOBJECT
+ FLAG_JSLENGTH
.{{foo.length}}
when foo is an array (simulate JavaScript Array.proto.length behavior){{var}}
. This option is same with handlbars.js noEscape option.{{..}}
or {{../foo}}
in template. Otherwise, {{..}}
or {{../foo}}
will cause template error.
\
.{{this}}
as {{.}}
. Otherwise, {{this}}
will lookup the variable 'this'.