-
Notifications
You must be signed in to change notification settings - Fork 100
Home
Flex Ferrum edited this page Apr 28, 2018
·
11 revisions
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:
-
Declare the jinja2::Template object: jinja2::Template tpl;
-
Populate it with template: tpl.Load("{{'Hello World' }}!!!");
-
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.