From 91cce88c912386cc632db6f39d2cf9f64d763534 Mon Sep 17 00:00:00 2001 From: Avital Oliver Date: Wed, 22 Jan 2014 15:43:35 -0800 Subject: [PATCH] Make {{#if content}} work. This lets you check whether a template was invoked via inclusion or as a block helper. An example is the api_box template in docs. --- packages/spacebars-compiler/spacebars-compiler.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/packages/spacebars-compiler/spacebars-compiler.js b/packages/spacebars-compiler/spacebars-compiler.js index e992d32094..f90923f821 100644 --- a/packages/spacebars-compiler/spacebars-compiler.js +++ b/packages/spacebars-compiler/spacebars-compiler.js @@ -302,6 +302,14 @@ var codeGenMustache = function (tag, mustacheType) { // // No code is generated to call the result if it's a function. var codeGenPath = function (path) { + // Let {{#if content}} check whether this template was invoked via + // inclusion or as a block helper. + if (builtInComponents.hasOwnProperty(path[0])) { + if (path.length > 1) + throw new Error("Unexpected dotted path beginning with " + path[0]); + return builtInComponents[path[0]]; + } + var code = 'self.lookup(' + toJSLiteral(path[0]) + ')'; if (path.length > 1) {