How to write a message to the console in Handlebars?

I work with Ember.js and wonder if there is a built-in function in Handlebars that allows me to print to the console like {{ log "my message" }} , similar to what we can currently do with journal objects like : {{ log this }}


Or do I need to define my helper function every time ?

But this does not even work for me ( click for jsbin ):

I have in Handlebars:

 {{ debug "this is my string" }} 

Then in app.js I have:

 Ember.Handlebars.helper('debug', function(the_string){ console.log(the_string); }); 

But app.js does not get the_string , so the_string is undefined, what happens?

+4
source share
2 answers

I'm not sure why Ember.Handlebars.helper does not work ... At the moment you can try

  Ember.Handlebars.registerHelper('debug', function(the_string){ Ember.Logger.log(the_string); // or simply console.log(the_string); }); 
+9
source

Just post a new answer for people who find this in the future. Now there is an easier way.

Your {{debug}} helper is effectively built in with the {{log}} built-in helper. You can also add a breakpoint using {{debugger}} .

See manuals for more details.

+2
source

Source: https://habr.com/ru/post/1485467/


All Articles