Underscore.js Template – Uncaught TypeError: Cannot read property ‘replace’ of undefined

underscore-js

This issue usually happens while using underscore.js function _.template() and it can’t find the HTML template. To solve this issue, make sure the HTML DOM is existed.

For example using jQuery:

<script type="text/html" id="tmpl-message">
    <div class="message"><%= data.message %></div>
</script>
var template = _.template( $("#tmpl-message").html() );	

Create Comment

Your email address will not be published. Required fields are marked *