A compiling HTML templating engine for Lua and OpenResty, featuring template inheritance, includes, and precompilation.
lua-resty-template is a templating engine for Lua and OpenResty that compiles HTML templates into Lua functions. It solves the need for dynamic server-side HTML generation in Lua-based web applications, offering features like template inheritance, includes, and precompilation for performance.
Lua developers building web applications with OpenResty or other Lua web frameworks, especially those needing server-side HTML rendering with layouts and reusable components.
Developers choose lua-resty-template for its speed (due to compilation), seamless OpenResty integration, and rich feature set like inheritance and macros, all while maintaining a simple syntax similar to other templating languages.
Templating Engine (HTML) for Lua and OpenResty.
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
Templates are compiled to Lua functions or binary bytecode, leading to fast execution as shown in benchmarks with low parsing and compilation times.
Seamlessly works with Nginx directives like template_root and template_location, optimizing template loading in OpenResty environments without extra configuration.
Supports multi-level inheritance, blocks, includes, and macros, enabling complex layouts and reusable components similar to modern templating engines.
Offers automatic HTML escaping in {{ }} tags for security and a safe mode that returns errors instead of throwing, plus a visitor API for custom parsing logic.
Requires understanding Nginx/OpenResty setup and template loading precedence (e.g., template_root vs. template_location), which can be error-prone for newcomers.
As a Lua-specific engine, it lacks the extensive plugin libraries, community tools, and learning resources available for more popular alternatives like Jinja2 or EJS.
Caching is enabled by default but requires manual clearing (template.cache = {}) during development or updates, adding operational complexity.
The README warns against using reserved context keys like ___, context, and echo, which can cause subtle bugs if overwritten, demanding careful attention.