stencet
v0.1.16
Build C++ web server modules that allow easy routing and deployment.
|
Template pages look like this:
test.tc:
header.tc:
Code inside of {% %} are tags which specify different commands, code inside of {{ }} are variables which are printed to the page.
Notice that some tags require end tags (for), and others don't (include).
Code to run that example could look like this:
test.cc:
Which outputs to std::cerr:
The templating engine doesn't care about the underlying engine – it could spit out CSS, HTML, XML, whatever.
The first argument of render just takes in a stream; so writing to files or general streams is pretty straightforward.
The variant type operates a lot like JSON objects. You can treat it like a map, a list, a string, a double, an int or a boolean so long as you are consistent (Don't try setting something to true after you've set a string value, for instance).
Variants are good for quick throw-together demos, but a lot of times you will probably want to use your own classes. You can either implement ViewModel, or add reflection to your class. After either of which, you can just pass it into the render function directly.