Skip to content

Instantly share code, notes, and snippets.

@lzilioli
Last active January 26, 2017 16:59
Show Gist options
  • Save lzilioli/18c74a0e01a74290a603e8c2256ff4cd to your computer and use it in GitHub Desktop.
Save lzilioli/18c74a0e01a74290a603e8c2256ff4cd to your computer and use it in GitHub Desktop.
Illustrates issue with if/else blocks in lnc 1.0
$ php --version
PHP 5.6.21 (cli) (built: May  4 2016 04:06:12)
Copyright (c) 1997-2016 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2016 Zend Technologies
    with Zend OPcache v7.0.6-dev, Copyright (c) 1999-2016, by Zend Technologies
    with Xdebug v2.4.0RC4, Copyright (c) 2002-2016, by Derick Rethans
Fatal error: Uncaught exception 'Exception' with message '{{else}} only valid in if, unless, each, and #section context' in error.php on line 45

Exception: {{else}} only valid in if, unless, each, and #section context in vendor/zordius/lightncandy/src/LightnCandy.php on line 108
{
"name": "lzilioli/lnc-else-conditional-error",
"description": "example setup for reproducing LnC #254",
"authors": [
{
"name": "Luke Zilioli",
"email": "[email protected]"
}
],
"require": {
"zordius/lightncandy": "v1.0.0"
}
}
{
"_readme": [
"This file locks the dependencies of your project to a known state",
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
"This file is @generated automatically"
],
"hash": "a55f035ab7305ad53be850e7f3d2c722",
"content-hash": "47de8736e64dffadd508e16c94e80ab1",
"packages": [
{
"name": "zordius/lightncandy",
"version": "v1.0.0",
"source": {
"type": "git",
"url": "https://github.com/zordius/lightncandy.git",
"reference": "42a3683aba7867a6b30b7179ab26ebcef93d34cc"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/zordius/lightncandy/zipball/42a3683aba7867a6b30b7179ab26ebcef93d34cc",
"reference": "42a3683aba7867a6b30b7179ab26ebcef93d34cc",
"shasum": ""
},
"require": {
"php": ">=5.4.0"
},
"require-dev": {
"phpunit/phpunit": "4.0.17"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.0.0-dev"
}
},
"autoload": {
"psr-4": {
"LightnCandy\\": "src"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Zordius Chen",
"email": "[email protected]"
}
],
"description": "An extremely fast PHP implementation of handlebars ( http://handlebarsjs.com/ ) and mustache ( http://mustache.github.io/ ).",
"homepage": "https://github.com/zordius/lightncandy",
"keywords": [
"handlebars",
"logicless",
"mustache",
"php",
"template"
],
"time": "2016-12-30 04:28:45"
}
],
"packages-dev": [],
"aliases": [],
"minimum-stability": "stable",
"stability-flags": [],
"prefer-stable": false,
"prefer-lowest": false,
"platform": [],
"platform-dev": []
}
#!/usr/bin/env php
<?php
error_reporting(E_ALL);
require_once('vendor/autoload.php');
use LightnCandy\LightnCandy;
$template = '
<div class="foo">
{{#if failed}}
failed
{{else if complete}}
complete
{{else }}
fallback
{{/if}}
<div class="bar
{{#if failed}}
failed
{{else if complete}}
complete
{{/if}}">
</div>
';
$phpStr = LightnCandy::compile($template, array(
'flags' => 0
| LightnCandy::FLAG_BESTPERFORMANCE
| LightnCandy::FLAG_ERROR_EXCEPTION
| LightnCandy::FLAG_RUNTIMEPARTIAL
| LightnCandy::FLAG_SPACECTL
| LightnCandy::FLAG_SPVARS
| LightnCandy::FLAG_HANDLEBARS
));
$output = eval('?><?php ' . $phpStr);
echo $output(array('failed'=>true));
echo $output(array('complete'=>true));
echo $output(array('current'=>true));
echo $output(array());
#!/usr/bin/env php
<?php
error_reporting(E_ALL);
require_once('vendor/autoload.php');
use LightnCandy\LightnCandy;
$template = '
<div class="foo">
{{#if failed}}
failed
{{else}}{{#if complete}}
complete
{{else}}
fallback
{{/if}}{{/if}}
<div class="bar
{{#if failed}}
failed
{{else}}{{#if complete}}
complete
{{/if}}{{/if}}">
</div>
';
$phpStr = LightnCandy::compile($template, array(
'flags' => 0
| LightnCandy::FLAG_BESTPERFORMANCE
| LightnCandy::FLAG_ERROR_EXCEPTION
| LightnCandy::FLAG_RUNTIMEPARTIAL
| LightnCandy::FLAG_SPACECTL
| LightnCandy::FLAG_SPVARS
| LightnCandy::FLAG_HANDLEBARS
));
$output = eval('?><?php ' . $phpStr);
echo $output(array('failed'=>true));
echo $output(array('complete'=>true));
echo $output(array('current'=>true));
echo $output(array());
#!/usr/bin/env php
<?php
error_reporting(E_ALL);
require_once('vendor/autoload.php');
use LightnCandy\LightnCandy;
$template = '
<div class="foo">
{{#if failed}}
failed
{{else if complete}}
complete
{{else }}
fallback
{{/if}}
</div>
';
$phpStr = LightnCandy::compile($template, array(
'flags' => 0
| LightnCandy::FLAG_BESTPERFORMANCE
| LightnCandy::FLAG_ERROR_EXCEPTION
| LightnCandy::FLAG_RUNTIMEPARTIAL
| LightnCandy::FLAG_SPACECTL
| LightnCandy::FLAG_SPVARS
| LightnCandy::FLAG_HANDLEBARS
));
$output = eval('?><?php ' . $phpStr);
echo $output(array('failed'=>true));
echo $output(array('complete'=>true));
echo $output(array('current'=>true));
echo $output(array());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment