They are cool! Let's look at them. partials
Well, it's a special language for a special purpose: templating. I wouldn't use it for general purpose programming, like networking or machine learning. But as a templating language, it's good. I don't know of any particular thing it's missing.
Well, Jinja2 has a feature called template inheritance, where you can have a base template, say with bootstrap and tailwind and your navbar and such all in it, and then just plug in pieces. That's pretty cool, though I'll admit that students struggle with it more than they do with EJS.
Two entirely separate worlds. EJS works on the back end (server side) while cloning is a front-end thing. They both have the same effect, and one can imagine a site that use both. Maybe EJS renders the basic page, and front-end templating is used with Ajax updates.
This is an important issue that we will talk more about later in the course. For
now, let's say that HTML can be used for attacking users, particularly
if it includes JS code, which it can with, say,
an onmouseover
attribute or even a
whole script
tag.
So, if we don't trust the HTML (it's coming from user-contributed data in the the database, say), we should escape it.
So stick to <%=
unless you know what you are doing.
but with partials, we wrote the HTML, so we can trust the code, and <%-
is appropriate.
Yes, I hope so!
Great! That was my goal. Some of the alternative templating engines (looking at you, Jade) are entirely new languages.