How can I display an object with all its keys and values in Blaze?


#1

Hi,

How can I display an object with all its keys and values in Blaze?
In angular I can do

{{currentUser | json}}

Thanks,


#2

Couldn’t you just make a global template helper called json which does JSON.parse?

Template.registerHelper('json', function (object) {
    return JSON.parse(object);
});

Then use it like so:

{{json currentUser}}

#3

Where is the correct place to define global template helpers?


#4

Template.registerHelper(‘json’, function (object) {
return JSON.stringify(object);
});


#5

Wherever you want!

I’ve got mine in /imports/startup/client/templateHelpers.js for a large app.

And just stick them in /client/main.js for small apps.

Structure helps you for large apps, don’t worry too much if it’s a small one