LightnCandy option: 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.

Sample Codes

compile to 'a' . $b . 'c' when do not use FLAG_ECHO

Used option: FLAG_JSTRUE

Data:
NULL
Template:
A{{{foo}}}C
Result:
use \LightnCandy\Runtime as LR;return function ($in = null, $options = null) {
    $helpers = array();
    $partials = array();
    $cx = array(
        'flags' => array(
            'jstrue' => true,
            'jsobj' => false,
            'jslen' => false,
            'spvar' => false,
            'prop' => false,
            'method' => false,
            'lambda' => false,
            'mustlok' => false,
            'mustlam' => false,
            'mustsec' => false,
            'echo' => false,
            'partnc' => false,
            'knohlp' => false,
            'debug' => isset($options['debug']) ? $options['debug'] : 1,
        ),
        'constants' => array(),
        'helpers' => isset($options['helpers']) ? array_merge($helpers, $options['helpers']) : $helpers,
        'partials' => isset($options['partials']) ? array_merge($partials, $options['partials']) : $partials,
        'scopes' => array(),
        'sp_vars' => isset($options['data']) ? array_merge(array('root' => $in), $options['data']) : array('root' => $in),
        'blparam' => array(),
        'partialid' => 0,
        'runtime' => '\LightnCandy\Runtime',
    );
    
    $inary=is_array($in);
    return 'A'.LR::raw($cx, (($inary && isset($in['foo'])) ? $in['foo'] : null)).'C';
};
Source Code
require('./vendor/autoload.php');
use LightnCandy\LightnCandy;
$template = "A{{{foo}}}C";

$php = LightnCandy::compile($template, array(
  "flags" => LightnCandy::FLAG_JSTRUE
));

echo $php

compile to echo 'a', $b, 'c' by default

Used option: FLAG_ECHO

Data:
NULL
Template:
A{{{foo}}}C
Result:
use \LightnCandy\Runtime as LR;return function ($in = null, $options = null) {
    $helpers = array();
    $partials = array();
    $cx = array(
        'flags' => array(
            'jstrue' => false,
            'jsobj' => false,
            'jslen' => false,
            'spvar' => false,
            'prop' => false,
            'method' => false,
            'lambda' => false,
            'mustlok' => false,
            'mustlam' => false,
            'mustsec' => false,
            'echo' => true,
            'partnc' => false,
            'knohlp' => false,
            'debug' => isset($options['debug']) ? $options['debug'] : 1,
        ),
        'constants' => array(),
        'helpers' => isset($options['helpers']) ? array_merge($helpers, $options['helpers']) : $helpers,
        'partials' => isset($options['partials']) ? array_merge($partials, $options['partials']) : $partials,
        'scopes' => array(),
        'sp_vars' => isset($options['data']) ? array_merge(array('root' => $in), $options['data']) : array('root' => $in),
        'blparam' => array(),
        'partialid' => 0,
        'runtime' => '\LightnCandy\Runtime',
    );
    
    $inary=is_array($in);
    ob_start();echo 'A',(($inary && isset($in['foo'])) ? $in['foo'] : null),'C';return ob_get_clean();
};
Source Code
require('./vendor/autoload.php');
use LightnCandy\LightnCandy;
$template = "A{{{foo}}}C";

$php = LightnCandy::compile($template, array(
  "flags" => LightnCandy::FLAG_ECHO
));

echo $php

See Also...