File: index.html

package info (click to toggle)
ctemplate 2.4-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,352 kB
  • sloc: cpp: 15,200; ansic: 1,058; sh: 592; makefile: 458; python: 205; lisp: 197; perl: 86
file content (111 lines) | stat: -rw-r--r-- 3,341 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
  <title>Ctemplate (formerly Google Template) System</title>

  <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  <link href="designstyle.css" type="text/css" rel="stylesheet">
  <style type="text/css">
  ol.bluelist li {
    color: #3366ff;
    font-family: sans-serif;
  }
  ol.bluelist li p {
    color: #000;
    font-family: "Times Roman", times, serif;
  }
  ul.blacklist li {  
    color: #000;
    font-family: "Times Roman", times, serif;
  }
  </style>
</head>
<body>

<h1> <a name="Ctemplate_System"></a>Ctemplate System </h1>
<center><strong>Status: Current</strong> &nbsp;
<small>(as of 25 April 2008)</small></center>
<br>

<p>Welcome to the C++ CTemplate system!  (This project was originally
called Google Templates, due to its origin as the template system used
for Google search result pages, but now has a more general name
matching its community-owned nature.)</p>

<p>As a quick start, here's a small but complete program that uses this
template library.  For more details see, the links below.</p>

<h3>Template file <code>example.tpl</code></h3>
<pre>
   Hello {{NAME}},
   You have just won ${{VALUE}}!
   {{#IN_CA}}Well, ${{TAXED_VALUE}}, after taxes.{{/IN_CA}}
</pre>

<h3>C++ program <code>example.cc</code></h3>
<pre>
   #include &lt;stdlib.h>
   #include &lt;string>
   #include &lt;iostream>
   #include &lt;ctemplate/template.h>
   int main(int argc, char** argv) {
      ctemplate::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) {
        dict.ShowSection("IN_CA");
      }
      std::string output;
      ctemplate::ExpandTemplate("example.tpl", ctemplate::DO_NOT_STRIP, &dict, &output);
      std::cout &lt;&lt; output;
      return 0;
   }
</pre>

<h3>Compiling and linking (using gcc)</h3>
<pre>
   gcc -o example example.cc -lctemplate_nothreads
</pre>

<p>I can use the "nothreads" library because <code>example.cc</code>
doesn't use threads.  If <code>example.cc</code> were threaded, I
would do something like this instead:</p>
<pre>
   gcc -o example example.cc -lctemplate -pthread
</pre>

<p>See the README for more details about the two different ctemplate
libraries.</p>


<h2>In-depth Documentation</h2>

<ol>
  <li> <A HREF="howto.html">Howto</A>: Introduction to the
       Ctemplate system, and a tutorial for using it. </li>

  <li> <A HREF="auto_escape.html">Auto Escape</A>: Guide to using
       the optional Auto Escape mode to protect your web application
       better against XSS.</li>

  <li> <A HREF="tips.html">Tips</A>: Advice, tips, and recommendations
       for best practices with templates, to make them easier to write
       and maintain, and to avoid common template mistakes. </li>

  <li> <A HREF="example.html">Examples</A>: Some example templates and
       application code that uses them.  These are taken from actual
       Google applications. </li>
</ol>

<hr>
<address>
Craig Silverstein<br>
Last modified: Mon Feb 22 10:59:03 PST 2010
</address>

</body>
</html>