Page 1 of 1

utemplate - Lightweight template engine for MicroPython

Posted: Sun Jun 01, 2014 4:45 pm
by pfalcon
I worked on this project in deep background for a while, and finally found time to polish it a little bit and push to github/PyPI. The idea is to have lightweight, memory-efficient, unbloated template engine for MicroPython. Unbloated means there's no template interpreter - why to have it, if there's already interpreter in MicroPython, just need to convert template to Python source, voila. Memory-efficient means that partial chunk-by-chunk template rendering should be supported, so template is compiled into a generator function.

Quick start:

Code: Select all

git clone https://github.com/pfalcon/utemplate
cd utemplate/examples
micropython ../utemplate_util.py run squares.tpl
Example of template:

Code: Select all

{% args %}
{% for i in range(5) %}
| {{i}} | {{"%2d" % i ** 2}} |
{% endfor %}
Output:

Code: Select all

| 0 |  0 |
| 1 |  1 |
| 2 |  4 |
| 3 |  9 |
| 4 | 16 |

Re: utemplate - Lightweight template engine for MicroPython

Posted: Sun Jun 08, 2014 1:17 pm
by pfalcon
Added include support:

Code: Select all

{% args %}
= Table of Squares =
{% include "squares.tpl" %}
====================

Re: utemplate - Lightweight template engine for MicroPython

Posted: Tue Jun 17, 2014 10:15 pm
by pfalcon
0.2.6 was posted on PyPI: https://pypi.python.org/pypi/utemplate/0.2.6 . Stats say 1260 monthly downloads ;-).

Re: utemplate - Lightweight template engine for MicroPython

Posted: Tue Aug 12, 2014 10:06 pm
by pfalcon
0.4 released on PyPI. Changes including dropping assumption of particular file extension for a template - any can be used now, which makes picoweb more compatible with Flask web microframework.

Re: utemplate - Lightweight template engine for MicroPython

Posted: Thu Nov 30, 2017 10:32 pm
by bitninja
Can the utemplate scripts be frozen into the ESP8266 build?

I have tried copying the compiled.py and source.py files into a sub-directory called utemplate in the \modules folder of the ESP8266 folder. But I am not sure that is the correct whey to install them.

I am definitely having issues running the examples that use the template rendering code.

Any ideas?

Thanks.

Re: utemplate - Lightweight template engine for MicroPython

Posted: Fri Dec 01, 2017 1:14 pm
by pfalcon
Of course they can be, see viewtopic.php?f=16&t=2966&p=20150#p20150 .

And someone needs to tweak the stuff to make picoweb's examples, which originally intended to be run with unix port, to run on ports where there's no "external command line" too, see https://github.com/pfalcon/picoweb/issues/15 and linked issues.

Re: utemplate - Lightweight template engine for MicroPython

Posted: Sat Feb 10, 2018 1:50 pm
by pfalcon
utemplate 1.2 was released: https://pypi.python.org/pypi/utemplate/1.2

It contains experimental support for includes using a name stored in a variable:

Code: Select all

{% include {{inc_name}} %}

Re: utemplate - Lightweight template engine for MicroPython

Posted: Thu May 09, 2019 2:11 pm
by nodepythoner
hello, how to use utemplate? i cant find documentation.

and i want to send variables to template, like here:
python code

Code: Select all

import picoweb
gc.collect()
app = picoweb.WebApp(__name__)
@app.route('/')
def index(req, resp):
   data='hello'
   yield from picoweb.start_response(resp)
   yield from app.render_template(resp,"index.html",(data,))


template

Code: Select all

<html>
<head>
</head>
<body>
{{data}}
</body>
</html>

Re: utemplate - Lightweight template engine for MicroPython

Posted: Wed Jun 12, 2019 7:01 am
by pfalcon
utemplate 1.3 was released: https://pypi.org/project/utemplate/1.3/ .

It's mostly a documentation update, at least a quick, but syntax reference is now included, etc. The doc is now also rendered on PyPI.