Skip to content

Commit ce3cd8a

Browse files
committed
Extend compiler-api example by replacing child-compiler
closes #1376
1 parent 33773c2 commit ce3cd8a

1 file changed

Lines changed: 10 additions & 3 deletions

File tree

docs/compiler-api.md

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ The `Handlebars.JavaScriptCompiler` object has a number of methods that may be c
300300

301301
This example changes all lookups of properties are performed by a helper (`lookupLowerCase`) which looks for `test` if `{{Test}}` occurs in the template. This is just to illustrate how compiler behavior can be change.
302302

303-
There is also [a jsfiddle with this code](https://jsfiddle.net/9D88g/85/) if you want to play around with it.
303+
There is also [a jsfiddle with this code](https://jsfiddle.net/9D88g/162/) if you want to play around with it.
304304

305305

306306
```javascript
@@ -309,6 +309,9 @@ function MyCompiler() {
309309
}
310310
MyCompiler.prototype = new Handlebars.JavaScriptCompiler();
311311

312+
// Use this compile to compile BlockStatment-Blocks
313+
MyCompiler.prototype.compiler = MyCompiler
314+
312315
MyCompiler.prototype.nameLookup = function(parent, name, type) {
313316
if (type === 'context') {
314317
return this.source.functionCall('helpers.lookupLowerCase', '', [parent, JSON.stringify(name)])
@@ -324,8 +327,12 @@ env.registerHelper('lookupLowerCase', function(parent, name) {
324327

325328
env.JavaScriptCompiler = MyCompiler;
326329

327-
var template = env.compile('{{#each Test}}{{.}} {{/each}}');
330+
var template = env.compile('{{#each Test}} ({{Value}}) {{/each}}');
328331
console.log(template({
329-
test: [ "a","b","c"]
332+
test: [
333+
{value: 'a'},
334+
{value: 'b'},
335+
{value: 'c'}
336+
]
330337
}));
331338
```

0 commit comments

Comments
 (0)