LightnCandy options

You can apply more options by running LightnCandy::compile($template, $options).

Example

Source Code
$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
));

Compile Flags:

LightnCandy::FLAG_ADVARNAME
Support {{foo.[0].[#te#st].bar}} or {{"some string"}} or {{helper (subexpression ...)}} handlebars style extensions.
LightnCandy::FLAG_BESTPERFORMANCE
same with FLAG_ECHO + FLAG_STANDALONEPHP now. This flag may be changed base on performance testing result in the future.
LightnCandy::FLAG_ECHO
compile to 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.
LightnCandy::FLAG_ELSE
Resolve {{else}} or {{^}} as handlebars specification. Otherwise, {{else}} will be resolved as normal variable, and {{^}} will cause template error.
LightnCandy::FLAG_ERROR_EXCEPTION
Throw exception when template error.
LightnCandy::FLAG_ERROR_LOG
Print error log to stderr when template error.
LightnCandy::FLAG_ERROR_SKIPPARTIAL
Skip 'partial not found' error or exception. Use this to align with mustache specification.
LightnCandy::FLAG_EXTHELPER
Do not including custom helper codes into compiled PHP codes. This reduces the code size, but you need to take care of your helper functions when rendering. If you forget to include required functions when execute rendering function, undefined function runtime error will be triggered.
LightnCandy::FLAG_HBESCAPE
Align {{foo}} escaping logic with handlebars.js. This causes ', = and ` be escaped in different way.
LightnCandy::FLAG_INSTANCE
same with FLAG_PROPERTY + FLAG_METHOD
LightnCandy::FLAG_JS
simulate all supported JavaScript behavior, same with FLAG_JSTRUE + FLAG_JSOBJECT + FLAG_JSLENGTH.
LightnCandy::FLAG_JSLENGTH
support {{foo.length}} when foo is an array (simulate JavaScript Array.proto.length behavior)
LightnCandy::FLAG_JSOBJECT
Align object or associative array conversion logic with JavaScript.
LightnCandy::FLAG_JSTRUE
Align boolean conversion logic with JavaScript.
LightnCandy::FLAG_METHOD
Support object instance attribute access; you must apply this if your data contains object.
LightnCandy::FLAG_NAMEDARG
Enable named arguments support for partials and helpers.
LightnCandy::FLAG_NOESCAPE
Do not do any HTML escape on {{var}}. This option is same with handlbars.js noEscape option.
LightnCandy::FLAG_PARENT
Support {{..}} or {{../foo}} in template. Otherwise, {{..}} or {{../foo}} will cause template error.
LightnCandy::FLAG_PARTIALNEWCONTEXT
Create a new context for the partial. This option is same with handlbars.js explicitPartialContext option.
LightnCandy::FLAG_PROPERTY
Support object instance attribute access; you must apply this if your data contains object.
LightnCandy::FLAG_RENDER_DEBUG
Generate debug template to show error when rendering. With this flag, the performance of rendering may be slowed.
LightnCandy::FLAG_RUNTIMEPARTIAL
Compile the partial as callable. This enables recursive partials or context change for partials.
LightnCandy::FLAG_SLASH
Skip a delimiter when it behind \ .
LightnCandy::FLAG_STANDALONEPHP
Generate stand-alone PHP codes which can be execute without LightnCandy\Runtime class. The compiled PHP code will contain scoped Runtime functions and the file size will be bigger. And, the performance will faster 5 ~10%.
LightnCandy::FLAG_THIS
Resolve {{this}} as {{.}} . Otherwise, {{this}} will lookup the variable 'this'.

See Also...