What is the <%= %>
tag in html?
There is none. There are several templating engines that use <%
and %>
to delimit either templates or code blocks, though: Active Server Pages (ASP), JavaServer Pages (JSP), probably others. Those usually do server-side processing and replace the text in the <% ... %>
with whatever should go there.
For instance, in your example
<h1><%= user.fullname %></h1>
if the user
object's fullname
property is "Joe Bloggs"
when the resource is requested, the engine will swap that in for that token before sending the text, so what the browser actually sees is
<h1>Joe Bloggs</h1>
In your case, as you point out, the processing is happening client-side. Your <% ... %>
tokens are within <script type="text/template">...</script>
blocks, so the <
isn't at all special. (Before DCoder pointed that out to me, I had a complex explanation here of why it worked...but then, er, DCoder pointed out that they were in script
blocks, so...)
DCoder also identified that these are templates being handled by backbone.js, which reuses underscore.js's templates.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…