Common Template Engine English | 中文 | Translate  
Downloads News Forums About Us
Documents
Overview
Template Guide
Expression Guide
Integration Guide
Config Guide
API Use Guide
Expansibility Guide
Architecture Guide
Dependency Lib
FAQ
Resources
Downloads
Changes Log
License
UML
Java Doc
Coverage Report
Community
Developer Team
Developer Team
Forums
Mail List
Bugs List
Report Bugs Here !
Support
CommonTemplate Use Guide


1. Using API JavaDoc>>
// import commontemplate module
import org.commontemplate.core.*;
import org.commontemplate.engine.*;
import org.commontemplate.standard.*;

import java.util.*;

// config and build factory
StandardConfiguration config = new StandardConfiguration();
config.loadStandardConfiguration();
config.set...
config.add...
...
Factory factory = new Engine(config);

// setting global context
GlobalContext globalContext = factory.getGlobalContext();
globalContext.defineVariable("name", "value");
...

// define data
Map model = ...
Appendable output = ...
Locale locale = ...
TimeZone timeZone = ...

// setting context
Context context = factory.createContext(output, locale, timeZone);
context.defineAllVariables(model);
context.defineVariable("name", "value");
...

// run
Template template = factory.getTemplate("mytemplate.mtl");
template.render(context);

// clean (try finally)
context.clear();
output.flush();
output.close();


Copyright © 2007-2008 CommonTemplate Team