Common Template Engine Release | Build >>  English | 中文
Downloads Changes Log Forums About Us
Documents
Overview
Template Reference
Expression Reference
Syntax Coat Reference
Config Guide
Expansion Guide
API Guide
FAQ
Versus Other Engine
Integration
MVC Integration
JSP Integration
Cache Integration
Logger Integration
Data Format
Javax Script Integration
Mail Sender Integration
Dependency Library
Tools
Debug Window
Viewer
Template Generator
Template Converter
Editor PlugIn
Code Case
Development
Architecture Specification
Develop Criterion
Project Planning
Requirement
Resources
Downloads
License
Changes Log
UML
Java Doc
Coverage Report
Community
Developer Team
Forums
Wiki
Mail List
Bugs List
Report Bugs Here !

 
Welcome to CommonTemplate

1. What's the CommonTemplate?
CommonTemplate is a "template engine",
a generic tool to generate text output: HTML, XML, Mail, Java source code, etc.

2. Which feature of CommonTemplate?
1) Only one syntax rule: $directive{expression}
2) WYSWYG in Dreamweaver and syntax coat is extensible.
3) Microkernel. Everything is additional except core API. Standard directives such as "for" and "if" could be replaced.
4) Better extensibility. The engine is just on the duty of translating the template into directive-tree. The directives will finish the rest of the job by themselves.

3. Where download CommonTemplate?
Download from SourceForge platform:
Download

4. How to write CTL? more...
Only one syntax rule: $directive{expression}
<html>
    <body>
        $if{users != null && users.size > 0}
        <table border="1">
            $for{user : users}
            <tr>
                <td>${for.index + 1}</td>
                <td>${user.name}</td>
                <td>${user.coins}</td>
            </tr>
            $end
        </table>
        $end
    </body>
</html>

HTML syntax coat: (WYSWYG)
(1) Comment Syntax Coat
<html>
    <body>
        <!--$if{users != null && users.size > 0}-->
        <table border="1">
            <!--$for{user : users}-->
            <tr>
                <td><!--$out{for.index + 1}-->1<!--$end--></td>
                <td><!--$out{user.name}-->james<!--$end--></td>
                <td><!--$out{user.coins}-->2.00<!--$end--></td>
            </tr>
            <!--$end-->
        </table>
        <!--$end-->
    </body>
</html>
(2) Attribute Syntax Coat
<html>
    <body>
        <table m:if="users != null && users.size > 0" border="1">
            <tr m:for="user : users">
                <td><span m:out="for.index + 1">james</span></td>
                <td><span m:out="user.name">james</span></td>
                <td><span m:out="user.coins">2.00</span></td>
            </tr>
        </table>
    </body>
</html>

5 .How to use CommonTemplate API? more...
(1) Java: (>=JRE1.5)
// 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();

(2) .Net: (>=CLR2.0)
......
 

Copyright © 2007 - 2009 CommonTemplate Developer Team