10

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.

Ankur Aggarwal
  • 2,993
  • 5
  • 30
  • 56

2 Answers2

14

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>
Coz
  • 558
  • 7
  • 15
  • thats the hard way around. Looking for a direct solution and JS file is not the exact replica of EJS code. It contains lots of self written code – Ankur Aggarwal Apr 13 '14 at 19:53
0

I always try to avoid doing serious calculation in ejs but one way to start is to check all of the arguments of can.view in the debugger before it enters the canjs. I find that I can usually figure out the issue from there.

ford prefect
  • 7,096
  • 11
  • 56
  • 83