3gwebtrain
3gwebtrain

Reputation: 15307

Handlebars - template keep getting error - "SyntaxError: Expected an identifier but found '(' instead"

In my app, i decide to use the Handlebars, I am using the requirejs and "shim" the handlebars. but i am keep getting a error as : "SyntaxError: Expected an identifier but found '(' instead" - i don't know what is the mistake i do..

requrijs:

requirejs.config({
    baseUrl: 'js',
    paths: {
        "jquery"    : 'lib/jquery-1.9.1.min',
        "underscore": "lib/underscore-min",
        "backbone"  : "lib/backbone-min",
        "handleBars": "lib/handlebars",
        "routers"   : "router/routers"
    },
    shim:{
        "underscore":{
            exports: '_'
        },
        "backbone":{
            exports: 'Backbone',
            deps:['underscore']
        },
        "handleBars":{
            exports: 'Handlebars',
            deps:['jquery', 'backbone']
        }
    }
});

require(["utils/utils","handleBars"],function (utils,handleBars) {

    var x = handleBars.compile($("#navi-template").html());
    console.log(x); //getting function
    console.log(x.({"name":"new name"})); //getting error.    
}); 

my template is :

<script id="navi-template" type="text/x-handlebars-template">
  <div class="subNavi">
        <ul>
            <li class="active"><a class="dashboard" href="#/general/dashBoard/">{{name}}</a></li>
        </ul>
    </div>   
</script>

any one figure out, the wrong what is going on here please?

Upvotes: 0

Views: 3954

Answers (1)

karthikr
karthikr

Reputation: 99660

Try this:

var context = {"name":"new name"}
console.log(x(context)); 

The . in x.(..) was the issue. (. is used for object attribute access)

You can find more about the usage in the example of the handlebarjs site

Upvotes: 1

Related Questions