I Use This!
Activity Not Available
Analyzed 7 months ago. based on code collected 12 months ago.

Project Summary

ctemplateCTemplate is 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.

Here's an example of how to use it: not complete, but gives a good feel for what the ctemplate API looks like.

Here is a simple template file:

Hello {{NAME}},
You have just won ${{VALUE}}!
{{#IN_CA}}Well, ${{TAXED_VALUE}}, after taxes.{{/IN_CA}}Here is a C++ program to fill in the template, which we assume is stored in the file 'example.tpl':

int main(int argc, char** argv) {
google::TemplateDictionary dict("example");
dict.SetValue("NAME", "John Smith");
int winnings = rand() % 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) {
google::Template* tpl = google::Template::GetTemplate("example.tpl",
std::string output;
tpl->Expand(&output, &dict);
std::cout << output;
return 0;
}If you are interested in this templating language but are programming in Java, consider Hapax, which is similar to ctemplate.

Recent news:

12 June 2009I've just released ctemplate 0.95. This is entirely an API cleanup release. Actually, relatively little of the API proper has changed: StringToTemplate no longer takes an autoescape-context arg (instead you specify this as part of the template-string, using the AUTOESCAPE pragma). A few obsolete constructs have gone away, such as the TemplateFromString class and TemplateDictionary::html_escape and friends (just use the top-level html_escape). See the ChangeLog for a full list of these changes.

The biggest change is a renaming: the default namespace is now ctemplate rather than google, and the include directory is ctemplate rather than google. Other namespaces, such as template_modifiers, have gone away.

All these changes will require you to modify your old code to get it working with ctemplate 0.95. I've written a script to help you do that. Please open an issue if you see a problem with the script. I've tested it, but not as widely as I'd like. Also note the script will not be perfect for more complex constructs, which you will have to clean up by hand.

I hope (expect) the API is now stable, and we won't see any more such changes before ctemplate 1.0. I tried to isolate them all in this release; except for the API changes, this release should behave identically to ctemplate 0.94.

7 May 2009I've just released ctemplate 0.94. A few new features have been added, such as the ability to expand a template into your own custom ExpandEmitter instance, and the ability to hook the annotation system (typically used for debugging). You can now remove strings from the template cache in addition to adding them. Also, there continues to be a trickle of new modifiers, in this case a modifier for URL's in a CSS context.

However, the most invasive changes were made for speed reasons. The biggest is that (almost) all TemplateDictionary allocations are now done on the arena -- this includes allocations by the STL classes inside the dictionary. This allows us to free all the memory at once, rather than item by item, and has yielded a 3-4% speed improvement in our tests. I've combined this with a small_map class that stores items in a vector instead of a hash-map until we get to 3 or 4 items; this gives another speed increase in the (common) case a template has only a few sections or includes.

I also changed the hashing code to use MurmurHash everywhere, rather than the string hash function built into the STL library. This should be faster.

All these changes should not be outwardly visible, but they do use more advanced features of C++ than ctemplate has to date. This may result in some problems compiling, or conceivably when running. If you see any, please file an issue report.

You can see a full list of changes on the ChangeLog.

20 August 2008ctemplate 0.91 introduces the beginning of some API changes, as I look to clean up the API in preparation for ctemplate 1.0. After 1.0, the API will remain backwards compatible, but until that time, the API may change. Please take a look at the ChangeLog to see if any of these changes affect you.

One change is the introduction of a new PerExpandData class, which holds some state that was formerly in the TemplateDictionary class. I'm still not sure if this class is a good idea, if it should be separate from TemplateDictionary or a member, or what functionality should move there (for instance, should SetTemplateGlobal move there, since template-global variables are really, in some sense, per-expand variables?) If you have any feedback, ideally based on your own experience using the current API, feel free to post it at google-ctemplate@googlegroups.com.

ctemplate also has several new features, including the addition of "separator" sections, and the ability to change the markup character (from {{). See the ChangeLog for a complete list, and the howto documentation for more details on these new features.


cplusplus google template templating

In a Nutshell, google-ctemplate...

 No recognizable code

Open Hub computes statistics on FOSS projects by examining source code and commit history in source code management systems. This project has code locations but that location contains no recognizable source code for Open Hub to analyze.

BSD 4-clause (University of California-Specific)

Commercial Use



Place Warranty


Hold Liable

Use Trademarks


Include Copyright

Include License

These details are provided for information only. No information here is legal advice and should not be used as such.

Project Security

Vulnerabilities per Version ( last 10 releases )

There are no reported vulnerabilities

Project Vulnerability Report

Security Confidence Index

Poor security track-record
Favorable security track-record

Vulnerability Exposure Index

Many reported vulnerabilities
Few reported vulnerabilities

Did You Know...

  • ...
    in 2016, 47% of companies did not have formal process in place to track OS code
  • ...
    you can subscribe to e-mail newsletters to receive update from the Open Hub blog
  • ...
    nearly 1 in 3 companies have no process for identifying, tracking, or remediating known open source vulnerabilities
  • ...
    search using multiple tags to find exactly what you need
About Project Security

 No recognizable code

Open Hub computes statistics on FOSS projects by examining source code and commit history in source code management systems. This project has code locations but that location contains no recognizable source code for Open Hub to analyze.

Community Rating

Be the first to rate this project
Click to add your rating
Review this Project!