Use C++ with Mustache

Ideal for C++ web applications!


Use C++ with Mustache


Mustache is a web template system with implementations available for several programming languages, including C++.

Mustache is described as a logicless system because it does not have any control flow instructions, however, both looping and conditional evaluation can be achieved using section tag processing lists and anonymous functions (lambdas).

Supported Features

This library supports all current Mustache features:

  • Variables
  • HTML escaping
  • Sections
  • Inverted Sections
  • True False
  • Lists
  • Lambdas
  • Partials
  • Comments
  • Set delimiter
  • Additional features:

    Custom escape function for use outside of HTML


Installation

The ease starts with installation, just:

git clone https://github.com/kainjow/Mustache
sudo install -v Mustache/mustache.hpp /usr/local/include/
rm -rf Mustache/

Usage

Create a file: main.cpp:

#include <iostream>
#include <mustache.hpp>

int main(){
   kainjow::mustache::mustache tmpl("Hello !");
   std::cout << tmpl.render({"what", "World"}) << '\n';
}

Alternatively you can use: using namespace kainjow::mustache; =}

Compile:

g++ main.cpp

Rotate:

./a.out

Probable output: Hello World!

If you want to test first:

git clone https://github.com/kainjow/Mustache
cd Mustache
sed -i "s/VERSION.*/VERSION $(cmake --version | grep -o [0-9].*))/g" CMakeLists.txt
cmake -B build .
cd build && make
./tests/mustache-unit-tests

For more information visit: https://github.com/kainjow/Mustache.


Alternatives to this Mustache:


cpp cppdaily web


Share


YouTube channel

Subscribe


Marcos Oliveira

Marcos Oliveira

Software developer
https://github.com/terroo

Related articles