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

Sample Codes

Default is to include used custom helpers into compiled PHP

Used option: FLAG_HANDLEBARS

Data:
NULL
Template:
{{foo}}
Result:
use \LightnCandy\SafeString as SafeString;use \LightnCandy\Runtime as LR;return function ($in = null, $options = null) {
    $helpers = array(            'foo' => function() {
      return 'Hello!';
    },
);
    $partials = array();
    $cx = array(
        'flags' => array(
            'jstrue' => false,
            'jsobj' => false,
            'jslen' => false,
            'spvar' => true,
            '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 ''.LR::encq($cx, LR::hbch($cx, 'foo', array(array(),array()), 'encq', $in)).'';
};

Check the code to know used helper codes

Source Code
require('./vendor/autoload.php');
use LightnCandy\LightnCandy;
$template = "{{foo}}";

$php = LightnCandy::compile($template, array(
  "flags" => LightnCandy::FLAG_HANDLEBARS,
  "helpers" => array(
    "foo" => function () {
      return 'Hello!';
    }
  ,  "bar" => function () {
      return 'World!';
    }
  )
));

echo $php

The generated code will not include custom helper

Used option: FLAG_HANDLEBARS FLAG_EXTHELPER

Data:
NULL
Template:
{{foo}}, {{bar}}
Result:
use \LightnCandy\SafeString as SafeString;use \LightnCandy\Runtime as LR;return function ($in = null, $options = null) {
    $helpers = array(            'foo' => 'foo',
            'bar' => 'bar',
);
    $partials = array();
    $cx = array(
        'flags' => array(
            'jstrue' => false,
            'jsobj' => false,
            'jslen' => false,
            'spvar' => true,
            '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 ''.LR::encq($cx, LR::hbch($cx, 'foo', array(array(),array()), 'encq', $in)).', '.LR::encq($cx, LR::hbch($cx, 'bar', array(array(),array()), 'encq', $in)).'';
};

Check the code to know used helper codes

Source Code
require('./vendor/autoload.php');
use LightnCandy\LightnCandy;
$template = "{{foo}}, {{bar}}";
function foo () {
    return 'Hello!';
}
function bar () {
    return 'World!';
}

$php = LightnCandy::compile($template, array(
  "flags" => LightnCandy::FLAG_HANDLEBARS | LightnCandy::FLAG_EXTHELPER,
  "helpers" => array(
  'foo','bar')
));

echo $php

Anonymous function will still be included in generated code

Used option: FLAG_HANDLEBARS FLAG_EXTHELPER

Data:
NULL
Template:
{{foo}}, {{bar}}
Result:
use \LightnCandy\SafeString as SafeString;use \LightnCandy\Runtime as LR;return function ($in = null, $options = null) {
    $helpers = array(            'bar' => 'bar',
            'foo' => function() {
      return 'Hello!';
    },
);
    $partials = array();
    $cx = array(
        'flags' => array(
            'jstrue' => false,
            'jsobj' => false,
            'jslen' => false,
            'spvar' => true,
            '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 ''.LR::encq($cx, LR::hbch($cx, 'foo', array(array(),array()), 'encq', $in)).', '.LR::encq($cx, LR::hbch($cx, 'bar', array(array(),array()), 'encq', $in)).'';
};

Check the code to know used helper codes

Source Code
require('./vendor/autoload.php');
use LightnCandy\LightnCandy;
$template = "{{foo}}, {{bar}}";
function bar () {
    return 'World!';
}

$php = LightnCandy::compile($template, array(
  "flags" => LightnCandy::FLAG_HANDLEBARS | LightnCandy::FLAG_EXTHELPER,
  "helpers" => array(
  'bar',  "foo" => function () {
      return 'Hello!';
    }
  )
));

echo $php

Anonymous function will still be included in generated code

Used option: FLAG_HANDLEBARS FLAG_EXTHELPER

Data:
NULL
Template:
{{foo}}, {{bar}}
Result:
use \LightnCandy\SafeString as SafeString;use \LightnCandy\Runtime as LR;return function ($in = null, $options = null) {
    $helpers = array(            'bar' => '1',
            'foo' => '1',
);
    $partials = array();
    $cx = array(
        'flags' => array(
            'jstrue' => false,
            'jsobj' => false,
            'jslen' => false,
            'spvar' => true,
            '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 ''.LR::encq($cx, LR::hbch($cx, 'foo', array(array(),array()), 'encq', $in)).', '.LR::encq($cx, LR::hbch($cx, 'bar', array(array(),array()), 'encq', $in)).'';
};

Check the code to know used helper codes

Source Code
require('./vendor/autoload.php');
use LightnCandy\LightnCandy;
$template = "{{foo}}, {{bar}}";

$php = LightnCandy::compile($template, array(
  "flags" => LightnCandy::FLAG_HANDLEBARS | LightnCandy::FLAG_EXTHELPER,
  "helpers" => array(
  'bar',  "foo" => 1)
));

echo $php

See Also...