FiveM mustache - Logic-less {{mustache}} templates in FiveM (Lua)

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

11 Likes

I don’t quite understand your question, you can read the README.md, it contains everything you need to know.

Example of use is:

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

I hope this answers your question, it’s a library and not a script in game.

It looks amazing @TigoDEV

1 Like

This is really cool. I will definitely consider using this for newly created resources.

1 Like

Neat release, syntax reminds me of twig for php.

1 Like

I love you

1 Like

Awesome @TigoDEV ! just what I was looking for.

I don’t suppose you know a way to do similar for beards?
I know there’s a short one available, but I’m after a long biker style one.

You realise this doesn’t have to do with actual mustaches right?

Oh wow :crazy_face: don’t I feel dumb, just when I think I’m gaining a little progress with all this stuff, fall back to feeling noobsville.

I first came across this on git when researching something (?), had a quick read though the whole thing, even found it funny he was putting a moustache on Micheal Jackson (imagine that).
Bookmarked it to follow up later, but then seen this thread, thought I’d give him a :+1: & ask about beards.

Wake up this morning and see your post, almost spat a mouth full of coffee laughing.
I’m sure everyones had these moments silly fkrs like me remind you of.

Ya gotta admit though, for someone learning, the picture & repeated “moustache” references paints a picture, just don’t understand the jargon yet :wink:

P.S. I seen one of Koil’s characters with a big moustache, thought this might be it.

2 Likes