Garces Garces - 5 months ago 17x
Javascript Question

Jade template with pure JavaScript

I am using jade template engine in my app and want to remove jquery to check performance. Cannot figure out how to do it with pure JS in this example.

Instead of using jquery as such:

var items = ['it1', 'it2', 'it3'];
var tmpl = require('views/list');
var html = tmpl({ items: App.items });

Template would look as:

each item in items
li= item


See this plunker, it is using pure javascript to display your items:

  var items = ['it1', 'it2', 'it3'];
  var ul = document.getElementById('itemsLists');
  function displayElem(element, index) {
    var li = document.createElement('li');
    t = document.createTextNode(element);
    li.innerHTML=li.innerHTML + element;

script to use after the body

After you can find some template engine js such as pure.js or blueimp to integrate the js into the html but with jade it's not always working (more pure html or ejs).