1
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
4
<title>Google Template System</title>
6
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
7
<link href="http://www.google.com/favicon.ico" type="image/x-icon"
9
<link href="designstyle.css" type="text/css" rel="stylesheet">
10
<style type="text/css">
14
font-family: sans-serif;
18
font-family: "Times Roman", times, serif;
22
font-family: "Times Roman", times, serif;
29
<h1> <a name="Google_Template_System"></a>Google Template System </h1>
30
<center><strong>Status: Current</strong>
31
<small>(as of 25 April 2008)</small></center>
34
Welcome to the Google C++ template system! As a quick start, here's a
35
small but complete program that uses this template library. For more
36
details see, the links below.
38
<h3>Template file <code>example.tpl</code></h3>
41
You have just won ${{VALUE}}!
42
{{#IN_CA}}Well, ${{TAXED_VALUE}}, after taxes.{{/IN_CA}}
45
<h3>C++ program <code>example.cc</code></h3>
47
#include <stdlib.h>
49
#include <iostream>
50
#include <ctemplate/template.h>
51
int main(int argc, char** argv) {
52
ctemplate::TemplateDictionary dict("example");
53
dict.SetValue("NAME", "John Smith");
54
int winnings = random() % 100000;
55
dict.SetIntValue("VALUE", winnings);
56
dict.SetFormattedValue("TAXED_VALUE", "%.2f", winnings * 0.83);
57
// For now, assume everyone lives in CA.
58
// (Try running the program with a 0 here instead!)
60
dict.ShowSection("IN_CA");
63
ctemplate::Template* tpl = ctemplate::Template::GetTemplate(
64
"example.tpl", ctemplate::DO_NOT_STRIP);
66
tpl->Expand(&output, &dict);
67
std::cout << output;
72
<h3>Compiling and linking (using gcc)</h3>
74
gcc -o example example.cc -lctemplate_nothreads
77
<p>I can use the "nothreads" library because <code>example.cc</code>
78
doesn't use threads. If <code>example.cc</code> were threaded, I
79
would do something like this instead:</p>
81
gcc -o example example.cc -lctemplate -pthread
84
<p>See the README for more details about the two different ctemplate
88
<h2>In-depth Documentation</h2>
91
<li> <A HREF="howto.html">Howto</A>: Introduction to the Google
92
Template system, and a tutorial for using it. </li>
94
<li> <A HREF="auto_escape.html">Auto Escape</A>: Guide to using
95
the optional Auto Escape mode to protect your web application
96
better against XSS.</li>
98
<li> <A HREF="tips.html">Tips</A>: Advice, tips, and recommendations
99
for best practices with templates, to make them easier to write
100
and maintain, and to avoid common template mistakes. </li>
102
<li> <A HREF="example.html">Examples</A>: Some example templates and
103
application code that uses them. These are taken from actual
104
Google applications. </li>
109
Craig Silverstein<br>
110
Last modified: Wed Feb 15 23:21:42 PST 2006