Link Search Menu Expand Document

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:

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:

  1. Include Jinja2C++ template declaration:
    #include <jinja2/template.h>
    
  2. Declare the jinja2::Template object:
    jinja2::Template tpl;
    
  3. Populate it with template:
    tpl.Load("{{'Hello World' }}!!!");
    
  4. 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";
}