- Clone https://github.com/zordius/lightncandy.git
- In the directory add the file
test.php
and edit it with the template and data you want. - Run
php test.php
and observe output.
Last active
August 29, 2015 14:23
-
-
Save joakin/e9220e0d18528c8cf040 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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!! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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 | |
)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Conditionals are properly supported 😕