10、ctemplate文档,简记(3)

简介: 1、AddSectionDictionary(section_name) returns a sub-dictionary associated with the given section_name (for instance, dict.AddSectionDictionary("MYSECT") for a template like {{#MYSECT}}...{{/MYSECT}}).     多次调用,每次将返回新字典。

1、AddSectionDictionary(section_name) returns a sub-dictionary associated with the given section_name (for instance, dict.AddSectionDictionary("MYSECT") for a template like {{#MYSECT}}...{{/MYSECT}}).

    多次调用,每次将返回新字典。每一次调用该函数,这个section将被展示一次。如果从没有调用过该函数,则section区域数据将不显示。

2、ShowSection() 用来显示section中的文字exactly once. It is equivalent to calling AddSectionDictionary() once, and ignoring the returned sub-dictionary. All variables in the section will depend on dictionary inheritence to get their values.(继承值)

3、SetValueAndShowSection() used to show a section if and only if a related variable is set to a non-empty value. SetValueAndShowSection(name, value, section_name) is equivalent to this: if value is empty do nothing, otherwise add a single dictionary to section_name and call section_dict->AddValue(name, value).

文档中有例子,还没有发现他有什么作用。

4、AddIncludeDictionary(section_name) returns a sub-dictionary associated with the given include_name (for instance, dict.AddIncludeDictionary("MYTPL") for a template like {{>MYTPL}}).

这个函数类同AddSectionDictionary,多次调用,每次返回新字典。调用之后,要记得调用SetFilename

5、Dump() and DumpToString() 用来调试。

6、The TemplateCache Class

holds a collection of templates.

7、老版本使用方法:

Template* tpl = Template::GetTemplate(filename, strip_mode);

TemplateDictionary dict(name);

tpl->Expand(&dict, &outstring);

新版本使用:

  std::string output;

  ctemplate::ExpandTemplate("example.tpl", ctemplate::DO_NOT_STRIP, &dict, &output);

  std::cout << output;

8、还可以通过指定AUTOESCAPE来指定模板的编码方法:

{{%AUTOESCAPE context="HTML"}}

9、还有类似lint的开发工具make_tpl_varnames_h

10、An included template is just a section whose contents are located in a separate file. You may iterate over it just like you do sections.

11、Since sections are hidden by default, you can use represent if-else logic in your code via ShowSection. For example:

     if ( my_test ) {

        dict->ShowSection(kxyz_TRUE_BLOCK);

        [ more code to fill the values for that section]

     } else {

        dict->ShowSection(kxyz_FALSE_BLOCK);

        [ more code to fill the values for that section]

     }

参考

1http://google-ctemplate.googlecode.com/svn/trunk/doc/reference.html

目录
相关文章
|
4月前
|
C语言
c语言编程练习题:7-52 求简单交错序列前N项和
c语言编程练习题:7-52 求简单交错序列前N项和
28 0
|
4月前
|
C语言
c语言编程练习题:7-32 求交错序列前N项和
c语言编程练习题:7-32 求交错序列前N项和
99 0
|
4月前
|
SQL 算法 vr&ar
☆打卡算法☆LeetCode 175. 组合两个表 算法解析
☆打卡算法☆LeetCode 175. 组合两个表 算法解析
|
4月前
|
存储 自然语言处理 算法
☆打卡算法☆LeetCode 211. 添加与搜索单词 - 数据结构设计 算法解析
☆打卡算法☆LeetCode 211. 添加与搜索单词 - 数据结构设计 算法解析
|
4月前
|
算法 vr&ar 图形学
☆打卡算法☆LeetCode 171. Excel 表列序号 算法解析
☆打卡算法☆LeetCode 171. Excel 表列序号 算法解析
|
10月前
|
存储 算法 数据可视化
关于B+树的介绍、用途和c++代码实现
关于B+树的介绍、用途和c++代码实现
|
10月前
|
人工智能
一文搞懂候选码、主码、全码、外码、主属性、主键、主关键字、非主属性清晰总结
一文搞懂候选码、主码、全码、外码、主属性、主键、主关键字、非主属性清晰总结
可以用树结构表达版本号
可以用树结构表达版本号
24 0
【集合论】序关系 ( 偏序集元素之间的关系 | 可比 | 严格小于 | 覆盖 | 哈斯图 )
【集合论】序关系 ( 偏序集元素之间的关系 | 可比 | 严格小于 | 覆盖 | 哈斯图 )
322 0
【集合论】序关系 ( 偏序集元素之间的关系 | 可比 | 严格小于 | 覆盖 | 哈斯图 )
|
机器学习/深度学习 JavaScript
宏程序常用结构
宏程序常用结构