https://github.com/tmpim/ltml
A simple and concise templating engine that takes advantage of elegant Lua syntax.
https://github.com/tmpim/ltml
dsl html lua template-engine templates web
Last synced: 14 days ago
JSON representation
A simple and concise templating engine that takes advantage of elegant Lua syntax.
- Host: GitHub
- URL: https://github.com/tmpim/ltml
- Owner: tmpim
- License: mit
- Created: 2019-06-10T01:54:05.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2023-11-25T02:39:38.000Z (about 2 years ago)
- Last Synced: 2025-10-19T10:03:50.179Z (4 months ago)
- Topics: dsl, html, lua, template-engine, templates, web
- Language: Lua
- Homepage:
- Size: 74.2 KB
- Stars: 11
- Watchers: 2
- Forks: 3
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# LTML
[](https://tmpim.github.io/ltml) [](https://travis-ci.org/tmpim/ltml) [](LICENSE) [](https://discord.gg/gd4KZvE)
A simple and concise templating engine that takes advantage of elegant Lua syntax.
## Explanation
LTML utilizes Lua's tables and optional parentheses around table and string literals to allow for a simple template syntax that can be easily rendered as HTML. LTML is portable enough to run in any typical Lua environment, given you can use `setfenv` (<5.1) or `load` (5.2+). It is even possible to [run LTML in the browser](https://github.com/tmpim/ltml-react).
## Example
```lua
def "cool_message" ( data.message:reverse() ),
def "groceries" { "Milk", "Eggs", "Bread" },
def "item" ( function(name) return li { name } end ),
doctype "html",
comment "This page was rendered with <3 by LTML",
html {
head {
title "LTML Example"
},
body {
h1 "LTML Example",
p { data.message },
p { cool_message },
br,
a { href = "https://justyn.is", "Check out my blog!" },
a { href = "https://github.com/tmpim/ltml" } "LTML is awesome!",
img { src = data.img },
h2 "Grocery list:",
ul {
map (groceries, item)
}
}
}
```
This renders to (prettified for readability):
```html
LTML Example
LTML Example
This page was created using only Lua (no HTML, JS) with LTML!
!LMTL htiw )SSC ,SJ ,LMTH on( auL ylno gnisu detaerc saw egap sihT
Check out my blog!
LTML is awesome!
Grocery list:
- Milk
- Eggs
- Bread
```
A more explanatory version of this template (and LTML as a whole) can be found in [ltml/example/example.ltml.lua](ltml/example/example.ltml.lua)
Example code for executing and rendering templates can be found in [ltml/example/example.lua](ltml/example/example.lua)
## Disclaimer
LTML is a very immature library, things are subject to change, and it is very much in testing, so utilize it with caution.
## Contributing
[Standard Lua style conventions](http://lua-users.org/wiki/LuaStyleGuide) should be followed when pushing to this repository.