Closed ticklemepierce closed 8 years ago
I actually can't find good documentation on what the behavior of this should be in Handlebars. In Mustache it's pretty clear, but I'm not sure the Handlebars docs say anything about using carrot (^
) with a block helper. Does this work as expected if you use {{^things}}...{{/things}}
instead?
It works as expected in that case, however the caret should invert every block.
This website lets you run handlebars code. I was able to invert both an if statement and a custom defined block helper.
HTML:
<script id="block-expressions-template" type="text/x-handlebars-template">
<p>{{#if code}}{{code}}{{else}}Test{{/if}}</p>
<p>{{^if code}}{{code}}{{else}}Test{{/if}}</p>
<p>{{#has code}}{{code}}{{else}}Test{{/has}}</p>
<p>{{^has code}}{{code}}{{else}}Test{{/has}}</p>
</script>
<div class="content-placeholder"></div>
JS:
$(function () {
// Grab the template script
var theTemplateScript = $("#block-expressions-template").html();
Handlebars.registerHelper('has', function(value, options) {
return options.fn(this);
});
// Compile the template
var theTemplate = Handlebars.compile(theTemplateScript);
// Define our data object
var context = {
"code": "test"
};
// Pass our data to the template
var theCompiledHtml = theTemplate(context);
// Add the compiled html to the page
$('.content-placeholder').html(theCompiledHtml);
});
The inverted ones should print Test
and the regular ones should print test
Fixed with 0.9.2.
Code (modified from the tests):
In this case output is
Goodbye cruel world!
as expected.However, if 'things' is modified to not be
None
, then the output should beGoodbye world!
The following code still outputsGoodbye cruel world!