{"id":1837,"date":"2013-02-13T14:00:00","date_gmt":"2013-02-13T20:00:00","guid":{"rendered":"http:\/\/www.wiredprairie.us\/blog\/?p=1837"},"modified":"2013-02-13T07:43:14","modified_gmt":"2013-02-13T13:43:14","slug":"how-to-debug-an-underscore-js-template","status":"publish","type":"post","link":"https:\/\/www.wiredprairie.us\/blog\/index.php\/archives\/1837","title":{"rendered":"How to debug an underscore.js template"},"content":{"rendered":"
Given a simple template like this:<\/p>\n
<<\/span>div<\/span> class<\/span>="solution"<\/span> data-question-id<\/span>="<%= model.get('Id') %>"<\/span>><\/span> \n <<\/span>div<\/span> class<\/span>="title"<\/span>><\/span><%<\/span>= model.get('Name'<\/span>) %><\/span><\/<\/span>div<\/span>><\/span>\n <<\/span>div<\/span> class<\/span>="company"<\/span>><\/span><%<\/span>= model.get('Company'<\/span>) %><\/span><\/<\/span>div<\/span>><\/span>\n <<\/span>div<\/span> class<\/span>="version"<\/span>><\/span><%<\/span>= model.get('Version'<\/span>) %><\/span><\/<\/span>div<\/span>><\/span>\n <<\/span>div<\/span> class<\/span>="detail"<\/span>><\/span><%<\/span>= model.get('Summary'<\/span>) %><\/span><\/<\/span>div<\/span>><\/span>\n <<\/span>div<\/span> class<\/span>="actions"<\/span>><\/span>\n <<\/span>a<\/span> href<\/span>="\/#solution\/<%= Id %>\/<%= model.get('Id') %>"<\/span>><\/span>Detail<\/<\/span>a<\/span>><\/span>\n <\/<\/span>div<\/span>><\/span>\n<\/<\/span>div<\/span>><\/span><\/pre>\nAnd using your favorite JavaScript interactive debugger (Visual Studio 2012 is my favorite when I\u2019m doing MVC 4 Razor development), just add a debugger statement within your template temporarily:<\/p>\n
<<\/span>div<\/span> class<\/span>="solution"<\/span> data-question-id<\/span>="<%= model.get('Id') %>"<\/span>><\/span>\n <%<\/span> debugger; %><\/span>\n <<\/span>div<\/span> class<\/span>="title"<\/span>><\/span><%<\/span>= model.get('Name'<\/span>) %><\/span><\/<\/span>div<\/span>><\/span><\/pre>\n