OpenSource For You

Basic usage

-

There are three types of tags available on the Underscore template. 1. interpolat­e <%= ... %>

This prints the contents of the variable or the result of the expression presented inside the tag. 2. evaluate <% ... %>

This interprets the JavaScript statements available inside the tag, by which we can provide logical structure to the template. 3. escape <%... %>

This is similar to interpolat­e but escapes the following characters: &, <, >, “, ‘ , and /

Let’s now look at how the above tags are used. I am using an Apache Web server and I keep the following HTML, JS and library files under the directory undertemp, which is under the webroot directory.

Figure 2 gives a very simple example that shows you the details of how to use a template.

Newspapers in English

Newspapers from India