Skip to content

Commit

Permalink
esamattis#54 - adding capability to use inline partials with --traver…
Browse files Browse the repository at this point in the history
…se flag
  • Loading branch information
kentmw committed Apr 12, 2016
1 parent a07032f commit 48f5dd9
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,21 @@ Example:
<p>I'm a partial</p>
```

## 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.
Expand Down
8 changes: 5 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}
});
}

Expand Down

0 comments on commit 48f5dd9

Please sign in to comment.