How to create templates with Javascript?


I would like to know if it is possible (and how to do it, if it is) templates with Javascript . Just like Facelets in JSF , where you create a template page and the others follow what was pre-established.

If anyone can indicate any material, I really appreciate it!


With Handlebars you'll be able to create js templates with ease!

See an example of its syntax/Usage:

<div class="entry">
  <div class="body">

Using {{template}} to make your markings.

Populating the template.

var context = {title: "My New Post", body: "This is my first post!"};
var html    = template(context);


<div class="entry">
  <h1>My New Post</h1>
  <div class="body">
    This is my first post!

Another framework that can do this is AngularJS, it is very complete it has:

  • Two-way Data Binding
  • Dependency Injection
  • Creating directives (HTML Extension) <- Template
  • Modularization and reuse (Controllers, Services and Filters)
Scroll to Top