Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Debug EJS code in Chrome/Safari

I am using EJS templates with CanJS and are looking for a way to debug my EJS code. Currently firebug can show me the syntax errors in EJS but in other browsers, I am not able to see anything.I need to go through my EJS file very carefully to solve the errors. I searched on web and found out about ejs_fulljslint https://code.google.com/p/embeddedjavascript/ , but not able to run this properly. I included the script into my HTML file but still wasn't getting any console errors. I am not able to find a demo of debugging on web.

Can anyone tell me how to debug my EJS code. If you can provide me any example, that will be highly appreciated.

like image 798
Ankur Aggarwal Avatar asked Mar 20 '14 20:03

Ankur Aggarwal


1 Answers

In the end, EJS just translates to JavaScript and therefore just placing a debugger; statement where you need it and opening developer tools, might do the trick for you. For example, to check on the i variable in a for loop you would place your debugger; like this:

<script type="text/ejs" id="todoList">
  <% for(var i = 0; i < todos.length; ++i) { %>
    <% debugger; %>
    <li><%= this[i].attr('description') </li>
  <% } %>
</script>
like image 193
Coz Avatar answered Oct 15 '22 02:10

Coz