Possible Duplicate:
Javascript templating engines?
I keep on stumbling upon javascript templating engines and I have no idea what is their purpose. Could anyone explain me like I were five what are those? Can front-end developer make use of these?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
JavaScript template engines are often used when writing thick JS-clients or as “normal” template engines when using server-side js like Node.js.
Instead of cluttering the code by generating HTML using string concatenating etc., you instead use a template and interpolate the variable in them.
For instance in the example bellow you pass in an array
footo the template engine which then interpolates (replaces the placeholder ${data}) with item i from the array foo:In frameworks like backbone.js you typically use a template to implement the view part of the MVC pattern.
There are many different types of template engines in JS. Some are direct ports of server-side frameworks like ERB, HAML etc. Others are developed specially to work with JavaScript i.e Pure
There is a debate of how much expressiveness the template engine should give you because putting logic in your templates is usually a bad thing. Because of this some template engines are specifically designed to not let you put logic in them i.e Mustache