FiveM mustache - Logic-less {{mustache}} templates in FiveM with Lua
What could be more logical awesome than no logic at all?
FiveM Mustache is an implementation of the lustache implementation of the mustache template system in Lua.
Mustache is a logic-less template syntax. It can
be used for HTML, config files, source code - anything. It works by expanding
tags in a template using values provided in a hash or object.
We call it “logic-less” because there are no if statements, else clauses, or for
loops. Instead there are only tags. Some tags are replaced with a value, some
nothing, and others a series of values.
For a language-agnostic overview of mustache’s template syntax, see the
mustache(5)
manpage.
Where to use Fivem Mustache?
You can use lustache to render mustache templates anywhere you can use Lua.
fxmanifest.lua
or __resource.lua
add @mustache/mustache.lua
Usage
Installation
Download FiveM Mustache place it in your server resource directory and rename it to mustache
.
Below is quick example how to use mustache:
manifest.lua or __resource.lua
server_scripts {
...
'@mustache/mustache.lua',
...
Then you can do the following in your lua code project:
local template = 'Here\'s an {{example}} of what you can do'
local renderedTemplate = Mustache.Render(template, {
example = 'README.md'
})
print(renderedTemplate)
-- Console output is: Here's an README.md of what you can do
In this example, the Mustache.Render
function takes two parameters: 1) the
mustache template and 2) a view_model
object
that contains the data and code needed to render the template.
Download
README
Download Resource
Source
This release is different from the usual releases, it is a script that can only be used in other scripts.
Regards,
Tigo
Thymon Arens