oo-template
v0.0.2
Published
Templating
Downloads
3
Readme
oo-template
Installation
npm install oo-template
Usage
<span class="welcome">Welcome back, <b>{{user.firstName}}</b></span>
var template = require("oo-template");
var render = template(document.querySelector(".welcome").outerHTML);
var html = render({
firstName: "Bart",
lastName: "Van Beurden"
});
// <span class="welcome">Welcome back, <b>Bart</b></span>
## Rendering lists
Logicless templating doesn't exist, so you might as well program it in javascript
```html
<li class="todo-item">{{description}}</li>
<div class="todo">
<h1>{{title}}</h1>
<ul class="todo">{{items}}</ul>
</div>
var template = require("oo-template")
var renderTodoItem = template(document.querySelector(".todo-item"));
var renderTodo = template(document.querySelector(".todo"));
var todo = {
title: "Todo",
items: ["write documentation", "test stuff"]
};
var html = renderTodo({
title: todo.title,
items: todo.items.map(renderTodoItem).join("")
});