Skip to content
Flex Ferrum edited this page Apr 28, 2018 · 11 revisions

Getting started

In order to use Jinja2Cpp in your project you have to:

  • Clone the Jinja2Cpp repository
  • Build it according with the instructions
  • Link with your project.

Usage of Jinja2Cpp in the code is pretty simple:

  1. Declare the jinja2::Template object: jinja2::Template tpl;

  2. Populate it with template: tpl.Load("{{'Hello World' }}!!!");

  3. Render the template: std::cout << tpl.RenderAsString(jinja2::ValuesMap{}) << std::endl;

and get: Hello World!!!

That's all!

The render procedure is stateless, so you can perform several renderings simultaneously in different threads. Even if you pass parameters:

Parameters could have the following types:

  • std::string/std::wstring
  • integer (int64_t)
  • double
  • boolean (bool)
  • Tuples (also known as arrays)
  • Dictionaries (also known as maps)

Tuples and dictionaries can be mapped to the C++ types. So you can smoothly reflect your structures and collections into the template engine.

Clone this wiki locally