LightnCandy option: safestring

Use safestring option to provide your own SafeString implementation or change the default LS classname when FLAG_STANDALONEPHP is enabled.

MySafeString

You should provide __toString(). If you use \LightnCandy\SafeString in your custom helper, it will be replaced by your safestring automatically.

Source Code
require_once('./vendor/autoload.php');
use LightnCandy\LightnCandy;

class MySafeString {
    public function __toString() {
        return 'Yes! You&me!';
    }
}

$template = "{{foo}}, {{bar}}";

$phpStr = LightnCandy::compile($template, array(
    'flags' => LightnCandy::FLAG_HANDLEBARS | LightnCandy::FLAG_STANDALONEPHP,
    'helpers' => array(
        'foo' => function () {
            return new MySafeString();
        },
        'bar' => function () {
            return new \LightnCandy\SafeString('He&She!');
        }
    ),
    'safestring' => 'MySafeString'
));

$renderer = LightnCandy::prepare($phpStr);
echo $renderer();

Rename LS class

If the class is not implemeted, then the \LightnCandy\SafeString class will be used.

Source Code
require_once('./vendor/autoload.php');
use LightnCandy\LightnCandy;

$template = "{{foo}}, {{bar}}";

$phpStr = LightnCandy::compile($template, array(
    'flags' => LightnCandy::FLAG_HANDLEBARS | LightnCandy::FLAG_STANDALONEPHP,
    'helpers' => array(
        'foo' => function () {
            return new MySafeString('You&Me!');
        },
        'bar' => function () {
            return new \LightnCandy\SafeString('He&She!');
        }
    ),
    'safestring' => 'MySafeString'
));

$renderer = LightnCandy::prepare($phpStr);
echo "The Code:\n$phpStr\n\n";
echo "===========================\nThe Output:\n" . $renderer();

See Also...