Search code examples
javascripthtmlbackbone.js

Unknown tags in HTML


In an example of backbone.js I find code in the HTML surrounded by <%= %>. I would like to know what syntax / language this is.

  <% if (managerName) { %>
    <li>
        <a href="#employees/<%= managerId %>">
            <div class="story">
                <b>View Manager</b><br/>
                <span class="metadata"><%= managerName %></span>
            </div>
            <img src="css/images/manager.png" class="action-icon"/>
        </a>
    </li>
  <% } %>

Sorry if this is basic question but googling it turns out to be harder than expected.


Solution

  • Since it is related to backbone.js, it would be an underscore.js template. Have a look here or here for some examples and more information on how to use it. One way to find out if it is used by a JavaScript templating engine would be to find out if it lives inside a <script> tag. It is quite likely that you copied that code snippet out of a script block that looked similar to this <script type="text/template"></script>, if it was an underscore.js template. I personally don't know any other JavaScript templating engines which use the exact same syntax as underscore.js, there could be another one out there.