layout | title | nav_order | description |
---|---|---|---|
default |
Getting Started |
2 |
How to quickly start using Jinja2C++ |
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.
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:{% 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 %}