Handlebars debugging or log

i find this helper to be quite useful

Handlebars.registerHelper(“debug”, function(optionalValue) {
    console.log(“Current Context”);
    console.log(“====================”);
    console.log(this);
    if (optionalValue) {
        console.log(“Value”);
        console.log(“====================”);
        console.log(optionalValue);
    }
});

then you can use it in two ways in your template..

just a simple

{{debug}}

which will print out the current context

or to inspect a single value

{{debug val}}

to just print out that value.

You can do the same for console.log like shown below…

Handlebars.registerHelper(“log”, function(something) {
console.log(something);
});
In template, add like shown
{{log specificationData}}
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s