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 !

 
Common Template Language(CTL) Reference

1. Syntax:
Only syntax rule:
$directiveName{expression}

2. Escape:
(1) \$ escape directive leader character
eg: \${name} output: ${name}
(2) \\ cancel the escape character
eg: \\${name} output: \value

3. Special Directives:
(1) Line Comment Directive:
$# comment text ...

(2) Block Comment Directive:
$*
    comment text ...
*$

(3) No Parse Block Directive:
$!
    no parse, eg: $if ...
!\$

(4) General End Block Directive:
$end

4. Standard Directives:
(1) Output Directives:
${user.name}
$msg{"home.title"}
$msg{"home.title", arg0, arg1}
(2) Condition Directives:
$if{user.name == "james"}
    ...
$elseif{ user.name == "kent"}
    ...
$else
    ...
$end
(3) Iteration Directives:
$cycle{color: "red", "blue", "green"}
$for{users, "user", "status"}
    ${color.next}
    $beak{for.count > 5}
    $continue{user.name == null}
    ${for.index} ${for.index} ${for.count} ${for.size} ${for.first} ${for.last} ${for.middle} ${for.even} ${for.odd}
    ${user.name}
$forelse
    have no users...
$end
(4) Variable Directives:
$var{name = "james"}
$set{name = "james"}
$init{name = "guest"}
(5) Include Directives:
$include{"common.mtl", (param1: value1, param2: value2)}
$inline{"common.mtl"}
$display{"article.txt"}
(6) Macro Directives:
$macro{"mymacro"}
    ...
$end
$import{mymacro : "mymacro.ctm"}
$-mymacro{param1: "value1", param2: "value2"}
$+mymacro{param1: "value1", param2: "value2"}
    ...
$end
(7) Extend Directives: Demo>>
$zone{"myzone"}
    ...
$end
$extend{"super.ctl"}
    $zone{"myzone"}
        $superzone
        ...
    $end
$end
(8) Block Directives:
$block{"myblock"}
    ...
$end
$show{"myblock"}
$using{mymacro : "myblock"}
(9) Dynamic Directives:
$exec{templateString}
$eval{expressionString}
(10) Debug Directives:
$stop
$time{"xxx_time"}
    ...
$end
$log{"debug messages..."}
$log{debug: "debug messages..."}
$log{info: "info messages..."}
$log{warn: "warn messages..."}
$log{error: "error messages..."}
(11) Filter Directives:
$compress
    ...
$end
$escape{"html", "js", "url", "base64"}
    ...
$end
$code{"java"}
    ...
$end
$keyword{"word1", "word2"}
    ...
$end

3. Html Syntax Cost:
(1) <!--$name{expression}--> Comment Directive
(2) <table m:if="users != null && users.size > 0">...<table> Attribute Directive (if, for, out)

4. Servlet Root Model:
Servlet Scope: param, header, request, session, cookie, application

5. For Example:
(1) Standard Syntax:
<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>

(2) Comment Syntax Cost:
<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>

(3) Attribute Syntax Cost:
<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>
 

Copyright © 2007 - 2009 CommonTemplate Developer Team