Provide simple if/else rendering logic.
This is a handlebars.js extension, mustache do not support this.
Used option: FLAG_ELSE
array(
"foo" => true
)
YES no
YES
require('./vendor/autoload.php');
use LightnCandy\LightnCandy;
$template = "{{#if foo}}YES{{else}}no{{/if}}";
$php = LightnCandy::compile($template, array(
"flags" => LightnCandy::FLAG_ELSE
));
$render = LightnCandy::prepare($php);
$data = array(
"foo" => true
);
echo $render($data);
{
"foo": true
}
YES no
YES
var Handlebars = require('handlebars');
var template = '{{#if foo}}YES{{else}}no{{/if}}';
var render = Handlebars.compile(template);
var data = {
"foo": true
};
console.log(render(data));
true
Used option: FLAG_ELSE
array(
"foo" => "String"
)
YES no
YES
require('./vendor/autoload.php');
use LightnCandy\LightnCandy;
$template = "{{#if foo}}YES{{else}}no{{/if}}";
$php = LightnCandy::compile($template, array(
"flags" => LightnCandy::FLAG_ELSE
));
$render = LightnCandy::prepare($php);
$data = array(
"foo" => "String"
);
echo $render($data);
{
"foo": "String"
}
YES no
YES
var Handlebars = require('handlebars');
var template = '{{#if foo}}YES{{else}}no{{/if}}';
var render = Handlebars.compile(template);
var data = {
"foo": "String"
};
console.log(render(data));
true
Used option: FLAG_ELSE
array(
"foo" => array(
1
)
)
YES no
YES
require('./vendor/autoload.php');
use LightnCandy\LightnCandy;
$template = "{{#if foo}}YES{{else}}no{{/if}}";
$php = LightnCandy::compile($template, array(
"flags" => LightnCandy::FLAG_ELSE
));
$render = LightnCandy::prepare($php);
$data = array(
"foo" => array(
1
)
);
echo $render($data);
{
"foo": [
1
]
}
YES no
YES
var Handlebars = require('handlebars');
var template = '{{#if foo}}YES{{else}}no{{/if}}';
var render = Handlebars.compile(template);
var data = {
"foo": [
1
]
};
console.log(render(data));
true
Used option: FLAG_ELSE
array(
"foo" => 1
)
YES no
YES
require('./vendor/autoload.php');
use LightnCandy\LightnCandy;
$template = "{{#if foo}}YES{{else}}no{{/if}}";
$php = LightnCandy::compile($template, array(
"flags" => LightnCandy::FLAG_ELSE
));
$render = LightnCandy::prepare($php);
$data = array(
"foo" => 1
);
echo $render($data);
{
"foo": 1
}
YES no
YES
var Handlebars = require('handlebars');
var template = '{{#if foo}}YES{{else}}no{{/if}}';
var render = Handlebars.compile(template);
var data = {
"foo": 1
};
console.log(render(data));
true
Used option: FLAG_ELSE
array(
"foo" => -1
)
YES no
YES
require('./vendor/autoload.php');
use LightnCandy\LightnCandy;
$template = "{{#if foo}}YES{{else}}no{{/if}}";
$php = LightnCandy::compile($template, array(
"flags" => LightnCandy::FLAG_ELSE
));
$render = LightnCandy::prepare($php);
$data = array(
"foo" => -1
);
echo $render($data);
{
"foo": -1
}
YES no
YES
var Handlebars = require('handlebars');
var template = '{{#if foo}}YES{{else}}no{{/if}}';
var render = Handlebars.compile(template);
var data = {
"foo": -1
};
console.log(render(data));
true
Used option: FLAG_ELSE
array(
"foo" => array(
"bar" => NULL
)
)
YES no
YES
require('./vendor/autoload.php');
use LightnCandy\LightnCandy;
$template = "{{#if foo}}YES{{else}}no{{/if}}";
$php = LightnCandy::compile($template, array(
"flags" => LightnCandy::FLAG_ELSE
));
$render = LightnCandy::prepare($php);
$data = array(
"foo" => array(
"bar" => NULL
)
);
echo $render($data);
{
"foo": {
"bar": null
}
}
YES no
YES
var Handlebars = require('handlebars');
var template = '{{#if foo}}YES{{else}}no{{/if}}';
var render = Handlebars.compile(template);
var data = {
"foo": {
"bar": null
}
};
console.log(render(data));
Used option: FLAG_ELSE
array(
"foo" => false
)
YES no
no
require('./vendor/autoload.php');
use LightnCandy\LightnCandy;
$template = "{{#if foo}}YES{{else}}no{{/if}}";
$php = LightnCandy::compile($template, array(
"flags" => LightnCandy::FLAG_ELSE
));
$render = LightnCandy::prepare($php);
$data = array(
"foo" => false
);
echo $render($data);
{
"foo": false
}
YES no
no
var Handlebars = require('handlebars');
var template = '{{#if foo}}YES{{else}}no{{/if}}';
var render = Handlebars.compile(template);
var data = {
"foo": false
};
console.log(render(data));
false
Used option: FLAG_ELSE
array(
"foo" => ""
)
YES no
no
require('./vendor/autoload.php');
use LightnCandy\LightnCandy;
$template = "{{#if foo}}YES{{else}}no{{/if}}";
$php = LightnCandy::compile($template, array(
"flags" => LightnCandy::FLAG_ELSE
));
$render = LightnCandy::prepare($php);
$data = array(
"foo" => ""
);
echo $render($data);
{
"foo": ""
}
YES no
no
var Handlebars = require('handlebars');
var template = '{{#if foo}}YES{{else}}no{{/if}}';
var render = Handlebars.compile(template);
var data = {
"foo": ""
};
console.log(render(data));
false
Used option: FLAG_ELSE
array(
"foo" => array(
)
)
YES no
no
require('./vendor/autoload.php');
use LightnCandy\LightnCandy;
$template = "{{#if foo}}YES{{else}}no{{/if}}";
$php = LightnCandy::compile($template, array(
"flags" => LightnCandy::FLAG_ELSE
));
$render = LightnCandy::prepare($php);
$data = array(
"foo" => array(
)
);
echo $render($data);
{
"foo": []
}
YES no
no
var Handlebars = require('handlebars');
var template = '{{#if foo}}YES{{else}}no{{/if}}';
var render = Handlebars.compile(template);
var data = {
"foo": []
};
console.log(render(data));
0
means false
Used option: FLAG_ELSE
array(
"foo" => 0
)
YES no
no
require('./vendor/autoload.php');
use LightnCandy\LightnCandy;
$template = "{{#if foo}}YES{{else}}no{{/if}}";
$php = LightnCandy::compile($template, array(
"flags" => LightnCandy::FLAG_ELSE
));
$render = LightnCandy::prepare($php);
$data = array(
"foo" => 0
);
echo $render($data);
{
"foo": 0
}
YES no
no
var Handlebars = require('handlebars');
var template = '{{#if foo}}YES{{else}}no{{/if}}';
var render = Handlebars.compile(template);
var data = {
"foo": 0
};
console.log(render(data));