Aspect

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.

Synopsis

Template syntax:

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

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

Installation

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

Development

Features