I know the answers people typically give, but I need a concrete example as to why they are needed.
The latest impression I'm getting (mostly from underscore.js) is that it makes the code more PHP like in that you can have <% %> like ?> in PHP
The idea is to make your code less like spaghetti and have a clear difference between presentation and logic. That's what everyone says, but I'm not sure why this warrants the need for a templating engine.
Why can't you just do this in pure javascript? All you need is a function that takes in data as arguments and you can do keep javascript syntax without inventing a new language, which seems ridiculous. For example you can just do:
populateTable(obj) {
$('#model').html('
<h2>' + obj.title + '</h2>' +
<ul> ... </ul>
}
This seems fine to me. It's a function dedicated to rendering a table using some model data that you pass into it. Why do we need to invent new syntax?