Here's a simple template:
<html><head><title>{{TITLE}}</title>{{META_TAGS}}</head>
<body>{{BODY}}</body>
Here's a dictionary that one could use to instantiate the template:
{"TITLE": "Template example",
"BODY": "This is a simple template example./nIt's boring",
"DATE": "11/20/2005"}
使用CTemplate 初始化字典,也可以修改键值.
然后实例化template,生成输出:
<html><head><title>Template example</title></head>
<body>This is a simple template example.
It's boring</body></html>
目的:程序功能和输出分离
可用于动态网页生成,但不限于此
clearsilver 也是类似的模板,但用于html生成,不提供 c++,提供c,phthon,perl等接口
有关CTemplate,可以下载源代码包,里面有简单的例子