wycats/handlebars.js — Issue #168: Functions support
Author: evil-shrike
Created: 2012-01-30 17:38:40+00:00
State: open

Let's consider the example:

var source = "

Title: {{title}}

";
var tmpl = Handlebars.compile(source);
var vm = { title: "xyz"};
var markup = tmpl(vm);

This works. But instead of passing json-object I need to supply an object which has functions instead of fields:

var vm = {
title: function() {
if (arguments.length > 0) {
this._title = arguments[0];
} else {
return this._title;
}
}
}

So in template I'm trying to use a function call:

var source = "

Title: {{title()}}

";

But this doesn't work. It throws:

Parse error on line 1:

Title: {{title()}}
Te
-----------------^
Expecting 'ID', got 'undefined'

What are my options?