We've Moved!
Google Ctemplate is now hosted at
code.google.com.
Our new homepage is located at
http://code.google.com/p/google-ctemplate.
Overview
The ctemplate package contains a library implementing a simple but
powerful template language for C++. It emphasizes separating logic
from presentation: it is impossible to embed application logic in this
template language.
Ctemplate is distributed under the terms of the
BSD License.
For downloads, news, and other information, visit our
Project Page
Example
This is by no means a complete example; it simply gives you a
feel for what the ctemplate API looks like.
Template file example.tpl:
Hello {{NAME}},
You have just won ${{VALUE}}!
{{#IN_CA}}Well, ${{TAXED_VALUE}}, after taxes.{{/IN_CA}}
C++ program example.cc:
#include
#include
#include
#include
int main(int argc, char** argv) {
google::TemplateDictionary dict("example");
dict.SetValue("NAME", "John Smith");
int winnings = random() % 100000;
dict.SetIntValue("VALUE", winnings);
dict.SetFormattedValue("TAXED_VALUE", "%.2f", winnings * 0.83);
// For now, assume everyone lives in CA.
// (Try running the program with a 0 here instead!)
if (1) {
dict.ShowSection("IN_CA");
}
google::Template* tpl = google::Template::GetTemplate("example.tpl",
google::DO_NOT_STRIP);
std::string output;
tpl->Expand(&output, &dict);
std::cout << output;
return 0;
}
|
|
Documentation
Ctemplate
documentation, including a howto, an example, and usage tips.
Download
For downloads, visit our
Project Page
Google Groups
|