Skip to content

Latest commit

 

History

History
71 lines (56 loc) · 1.67 KB

getting_started.md

File metadata and controls

71 lines (56 loc) · 1.67 KB
layout title nav_order description
default
Getting Started
2
How to quickly start using Jinja2C++

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>
  1. Declare the jinja2::Template object:
jinja2::Template tpl;
  1. Populate it with template:{% raw %}
tpl.Load("{{'Hello World' }}!!!");
```{% endraw %}
4. Render the template:
```c++
std::cout << tpl.RenderAsString(jinja2::ValuesMap{}).value() << std::endl;

and you will get:

Hello World!!!

That's all!

Full-featured trivial sample source:{% raw %}

#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";
}
```{% endraw %}