Skip to content

Instantly share code, notes, and snippets.

@joakin
Last active August 29, 2015 14:23
Show Gist options
  • Save joakin/e9220e0d18528c8cf040 to your computer and use it in GitHub Desktop.
Save joakin/e9220e0d18528c8cf040 to your computer and use it in GitHub Desktop.
lightncandy (master %=) $ php test.php
Template is:
{{#winner}}Welcome {{name}},{{/winner}}{{^winner}}Hellow stranger,{{/winner}}
You win ${{value}} dollars!!
Welcome John,
You win $10000 dollars!!
Hellow stranger,
You win $10 dollars!!
<?php
require_once('src/lightncandy.php');
$flags = LightnCandy::FLAG_MUSTACHE | LightnCandy::FLAG_ERROR_EXCEPTION | LightnCandy::FLAG_RUNTIMEPARTIAL;
$template = "
{{#winner}}Welcome {{name}},{{/winner}}{{^winner}}Hellow stranger,{{/winner}}
You win \${{value}} dollars!!\n";
$php = LightnCandy::compile($template, Array(
'flags' => $flags,
));
$renderer = LightnCandy::prepare($php);
echo "Template is:\n$template\n\n";
echo $renderer(Array(
'winner' => Array(
'name' => 'John',
),
'value' => 10000
));
echo $renderer(Array(
'value' => 10
));
@joakin
Copy link
Author

joakin commented Jun 17, 2015

Conditionals are properly supported 😕

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment