Getting started
How to get Jinja2++
Get the latest Conan.io package: jinja2cpp/1.2.1
Or download the latest release: Release 1.2.1
Or:
- Clone the Jinja2C++ repository
- Build it according to the instructions
- Link it with your project.
A basic example
Simple example project with Jinja2C++ usage can be found here: https://github.com/jinja2cpp/examples-build/tree/master/conan/1.1.0
Using Jinja2C++ in your code is pretty simple:
- Include Jinja2C++ template declaration:
#include <jinja2/template.h>
- 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{}).value() << std::endl;
and you will get:
` Hello World!!! `
That’s all!
Full-featured trivial sample source:
#include <jinja2cpp/template.h>
#include <iostream>
int main()
{
std::string source = R"(
{{ ("Hello", 'world') | join }}!!!
{{ ("Hello", 'world') | join(', ') }}!!!
{{ ("Hello", 'world') | join(d = '; ') }}!!!
{{ ("Hello", 'world') | join(d = '; ') | lower }}!!!)";
jinja2::Template tpl;
tpl.Load(source);
std::string result = tpl.RenderAsString(jinja2::ValuesMap()).value();
std::cout << result << "\n";
}