9. ctemplate document, short note (2)

Source: Internet
Author: User

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 }}).

After multiple calls, a new dictionary is returned each time. This section is displayed every time this function is called. If this function has never been called, the data in the section area is not displayed.

2. showsection () is used to display the text exactly once in the Section. 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. (inherited value)

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 ).

There are examples in the document, and no function has been found.

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

This function is similar to addsectiondictionary. It is called multiple times and a new dictionary is returned each time. After the call, remember to call setfilename.

5. Dump () and dumptostring () are used for debugging.

6. The templatecache class

Holds a collection of templates.

7. Usage of earlier versions:

Template * TPL = template: gettemplate (filename, strip_mode );

Templatedictionary dict (name );

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

New Version:

STD: String output;

Ctemplate: expandtemplate ("example. TPL", ctemplate: do_not_strip, & dict, & output );

STD: cout <output;

8. You can also specify the template encoding method by specifying autoescape:

{{% Autoescape context = "html "}}

9. There is also a lint-like development tool make_tpl_varnames_h.

Reference

[1]Http://google-ctemplate.googlecode.com/svn/trunk/doc/reference.html

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.