From 48f5dd93cf23a2f46249976b5444cd8f9b958782 Mon Sep 17 00:00:00 2001 From: Kent Willis Date: Tue, 12 Apr 2016 17:37:11 -0400 Subject: [PATCH] #54 - adding capability to use inline partials with --traverse flag --- README.md | 15 +++++++++++++++ index.js | 8 +++++--- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 76f14ff..66dc695 100644 --- a/README.md +++ b/README.md @@ -83,6 +83,21 @@ Example:

I'm a partial

``` +## Inline Partials + +If you are using Handlebars 4.0.0 or later, you can still use inline partials. To denote a usage of an inline partial (and not a node_module dependency) just add 'inline:' to the beginning of the partial reference. + +Example: +```html +{{#*inline "myPartial"}} + My Content +{{/inline}} +{{#each children}} + {{> inline:myPartial}} +{{/each}} +``` + + ## package.json Transform can be configured from the package.json too. diff --git a/index.js b/index.js index 864634e..aba5873 100644 --- a/index.js +++ b/index.js @@ -136,9 +136,11 @@ function compile(file, opts) { if (partials && partials.length) { partials.forEach(function(p, i) { - var ident = "partial$" + i; - compiled += "var " + ident + " = require('" + p + "');\n"; - compiled += "HandlebarsCompiler.registerPartial('" + p + "', " + ident + ");\n"; + if (i.indexOf('inline:') !== 0) { + var ident = "partial$" + i; + compiled += "var " + ident + " = require('" + p + "');\n"; + compiled += "HandlebarsCompiler.registerPartial('" + p + "', " + ident + ");\n"; + } }); }