You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+13-13Lines changed: 13 additions & 13 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -29,7 +29,7 @@
29
29
30
30
Inja is a template engine for modern C++, loosely inspired by [jinja](http://jinja.pocoo.org) for python. It has an easy and yet powerful template syntax with all variables, loops, conditions, includes, callbacks, comments you need, nested and combined as you like. Inja uses the wonderful [json](https://github.com/nlohmann/json) library by nlohmann for data input and handling. Most importantly, *inja* needs only two header files, which is (nearly) as trivial as integration in C++ can get. Of course, everything is tested on all relevant compilers. Here is what it looks like:
Inja is a headers only library, which can be downloaded from the [releases](https://github.com/pantor/inja/releases) or directly from the `include/` or `single_include/` folder. Inja uses `nlohmann/json.hpp` as its single dependency, so make sure it can be included from `inja.hpp`. json can be downloaded [here](https://github.com/nlohmann/json/releases). Then integration is as easy as:
42
42
43
-
```c++
43
+
```.cpp
44
44
#include <inja.hpp>
45
45
46
46
// Just for convenience
@@ -67,7 +67,7 @@ This tutorial will give you an idea how to use inja. It will explain the most im
67
67
68
68
The basic template rendering takes a template as a `std::string` and a `json` object for all data. It returns the rendered template as an `std::string`.
69
69
70
-
```c++
70
+
```.cpp
71
71
json data;
72
72
data["name"] = "world";
73
73
@@ -76,7 +76,7 @@ render_to(std::cout, "Hello {{ name }}!", data); // Prints "Hello world!"
76
76
```
77
77
78
78
For more advanced usage, an environment is recommended.
In the default configuration, no whitespace is removed while rendering the file. To support a more readable template style, you can configure the environment to control whitespaces before and after a statement automatically. While enabling `set_trim_blocks` removes the first newline after a statement, `set_lstrip_blocks` strips tabs and spaces from the beginning of a line to the start of a block.
251
251
252
-
```c++
252
+
```.cpp
253
253
Environment env;
254
254
env.set_trim_blocks(true);
255
255
env.set_lstrip_blocks(true);
@@ -260,7 +260,7 @@ With both `trim_blocks` and `lstrip_blocks` enabled, you can put statements on t
260
260
### Callbacks
261
261
262
262
You can create your own and more complex functions with callbacks.
0 commit comments