UNPKG

1.86 kBMarkdownView Raw
1# Temple
2
3A JavaScript view framework.
4
5* __Reactive__ - Powered by [Trackr](https://github.com/beneaththeink/trackr), Temple automatically updates the DOM as data changes.
6* __Template Driven__ - Use a Mustache-HTML hybrid syntax to quickly generate UI scaffolding.
7* __Modular & Extensible__ - All views are encapsulated, reusable components.
8* __Data Neutral__ - Temple can be easily integrated with existing frameworks and platforms.
9
10## Example
11
12Here is a basic example of using Temple. This just uses a simple variable, but Temple has support for most of the major [Mustache features](http://mustache.github.io/mustache.5.html).
13
14```javascript
15// create a view instance from a template and data
16var tpl = Temple.render("<h1>Hello {{ name }}</h1>", { name: "World" });
17
18// render and append to the document body
19tpl.paint("body");
20
21// later, change the value and watch it auto-update the DOM
22tpl.data.name = "John";
23```
24
25Listening for DOM events is really easy in Temple. Enable the plugin and then add an `on-<event>` attribute to any element.
26
27```javascript
28// create a view instance from just a template
29var tpl = Temple.render("<a href='#' on-click='alert'>Click Me</a>")
30
31// enable the DOM events plugin
32.use("actions")
33
34// add the special alert action
35.addAction("alert", function(e) {
36 e.original.preventDefault();
37 alert("You clicked me!");
38})
39
40// render and append to the document body
41.paint("body");
42```
43
44Temple even lets you turn your views into reusable components.
45
46```javascript
47// a reusable View class
48var Hello = Temple.extend({
49 template: "Hello {{ name }}"
50});
51
52// render a new template that uses the view as a partial
53var tpl = Temple.render("<h1>{{> hello }}</h1>", { name: "John" })
54.setPartial("hello", Hello)
55.paint("body");
56
57// views can also be rendered directly
58var tpl2 = new Hello({ name: "World" }).paint("body");
59```
\No newline at end of file