Find file History
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.

jsdef - templetor extensions to support javascript templating

jsdef extension adds a new block jsdef to templetor syntax. The jsdef block defines a template function and also generates an equivalent JavaScript function.

This extension works only with the development branch of

How to use

Tell to use the extension.

import web
import jsdef

render = web.template.render("templates", extensions=[jsdef.extension])

Include jsdef.js in your site template.

And use jsdef in your templates.

$def with (page)


$jsdef render_books(books):
        $for book in books:
            <li><a href="$book.key">$book.title</a></li>

<div class="books">
    $# Above jsdef block has defined render_books template function. Use it when rendering the template.

<script type="test/javascript">
    function update_books(books) {
        // Above jsdef block has generated javascript for render_books function. Use it at the client.
        document.getElementById("books").innerHTML = render_books(books);


This is just an attempt to drive JavaScript templating from Python. Features like multiple assignments, list slicing, list comprehensions won't work.

If you are using a python function inside the jsdef block, you need to provide the equivalent in JavaScript too. Some builtin functions are already provided by jsdef.js.