Aspect is a compiling template engine for Lua and LuaJIT.

Latest release v2.2

Aspect a compiling (to Lua code and bytecode) a template engine for Lua and LuaJIT. Adapted to work with OpenResty and Tarantool. Lua itself is a simple language, but with many limitations and conventions.

Aspect makes it easy to work with Lua, letting you focus on the design of templates. Template syntax is very popular. This syntax is used in Twig, Jinja, Django, Liquid.

Yet another template engine? Yes. But more powerful than any other template engines. Just check out all the features.


Template syntax:

<!DOCTYPE html>
        {% block head %}
            <title>{{ page.title }}</title>
        {% endblock %}
        {% block content %}
            <ul id="navigation">
            {% for item in navigation %}
                <li><a href="{{ item.href }}">
                    {{- item.caption|escape -}}
            {% endfor %}
            <h1>My Webpage</h1>
            {{ page.body }}
        {% endblock %}
        <footer>{% include "footer.view" %}</footer>

Lua API:

local aspect = require("aspect.template").new(options)
local result, error 
    = aspect:eval("<div>Hello, {{ username }}</div>", vars)

Command line:

$ aspect /path/to/data.json /path/to/template.tpl


Using LuaRocks

Installing Aspect using LuaRocks is simple:

luarocks install aspect

Without LuaRocks

Or add src/?.lua to package.path:

package.path = '/path/to/aspect/src/?.lua;' .. package.path