Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/lucemia/doT

A python implementation of doT.js
https://github.com/lucemia/doT

Last synced: 4 months ago
JSON representation

A python implementation of doT.js

Awesome Lists containing this project

README

        

doT.py
======

A python implementation of the famous js template engine. doT.js. http://olado.github.io/doT/index.html.
It do excetly the same thing as doT.js except written in python. Thus, it can be used in python web framework.

doT.py compile the template to a pure javascript function in server side; therefore client side can evaluate the template later without any dependency. Which means it saves the time for client to load template engine and to load template file. In short, doT.py allows using client side template tech without include a template engine in client side.

## Installation

`pip install doT-js-py`

### Here is an example:

#### Use client side template

```html

// Compile template function
var tempFn = doT.template("<h1>Here is a sample template {{=it.foo}}</h1>");
var resultText = tempFn({foo: 'with doT'});
document.getElementById('container').innerHtml = resultText;

```

#### Use doT.py, you write:
```html

// Compile template function
var tempFn = {{ js_template('<h1>Here is a sample template {{=it.foo}}</h1>') }};
var resultText = tempFn({foo: 'with doT'});
document.getElementById('container').innerHtml = resultText;

```

#### it will automatically compiled to
```html

// Compile template function
var tempFn = function anonymous(it) { var out='"<h1>Here is a sample template '+(it.foo)+'</h1>"';return out; };
var resultText = tempFn({foo: 'with doT'});
document.getElementById('container').innerHtml = resultText;

```

Django Support:

Jinja2 Support:

Commandline Support: