a template engine for c++
- Variables
{$variable}
- Loops:
{% for person in people %}Name: {$person.name}{% endfor %}
- If:
{% if person.name == "xu" %}Full name: xu{% endif %}
cpptempl::auto_data data;
data["age"] = 10;
data["name"] = "xu";
std::string str = "name:{$name}, age:{$age}";
std::string ret = cpptempl::parse(str, data); // ret will be "name:xu, age:10"
The single required source, file cpptempl.h is in the src directory, All you need to do is add
#include "cpptempl.hpp"
The type of the variable is determined automatically by the expression to store. Likewise, the stored value is implicitly converted.
// number
cpptempl::auto_data t = 1;
int i = t;
// string
std::string str = "test";
cpptempl::auto_data s = str;
std::string str2 = s;
// boolean
bool b = true;
cpptempl::auto_data cb = b;
bool b2 = cb;