Template Tags

The code generator processes the following template tags inside the templates to generate the working codes, intermediate or advanced users can make use of these tags to create custom templates. These tags are case-insensitive. All template tags have the same basic syntax:

Syntax:

<!--##...##-->

Due to the HTML comment style format, these script blocks will be treated as HTML comments in any editors. Therefore, you can use your favorite editor to edit the template provided that these special tags are kept in place.

It is important to understand how templates tags works. The new template format is very simple. If you know how ASP or PHP works, you know how template work, because they work in the same way. During code generation, the code generator reads the template file, executes the scripts in the template tags, and finally, write the codes to the output file, like ASP or PHP outputs HTML to browser.

There are 6 types of template tags, the last 3 are just special cases of the 3rd type (function block). So it is very easy to use and learn.

 

1. Session Tags

Syntax:

<!--##session session_name##-->
...session content here...
<!--##/session##-->

Note that:

  1. The keyword "session" is immediately after the start tag "<!--##",
  2. The session_name is the name of the session, only alphanumerical characters should be used, no spaces, and it is not quoted,
  3. The tags must be in pairs, with a start session tag and an end session tag,
  4. The end session tags contain a "/" immediately after the tag "<!--##".

The code generator locates the source of a output file according to the sequence of sessions specified in the control.xml of the template. Each session tag carries a session name that identifies the lines of code that will be extracted.


2. Script Block

To generate codes according to the project settings, there are many script blocks in each session. Each script block is enclosed by special start and end tags.

Syntax:

<!--##
...Script here...
##-->

The script block syntax is analogous to the <% ... %> tags in ASP or <? ... ?> in PHP. The scripting language used in the script block is VBScript provided by Windows Script.

Windows Script
Windows Script is a comprehensive scripting infrastructure for the Microsoft® Windows® platform. This component is shipped with Internet Explorer and other Microsoft products. However, it is recommended that you download the latest version from Microsoft:
http://msdn.microsoft.com/library/default.asp?url=/downloads/list/webdev.asp
To customize template, you need to know VBScript, we recommend you to download the documentation from above page also.

In a script block, you can create variables and constants, use conditional statements, do looping, write procedures, etc. You can also access all settings in the project within the script block. (See Template Object Properties for details.) With script blocks, you can generate virtually any codes you want.

Example

<!--##If TABLE.TblType = "VIEW" Then##-->
...code here...
<!--##End If##-->

In this example the codes in between will only be generated if the table is a view. "TABLE" is a template object and "TblType" is one of its properties,

 

3. Function Block

Function block output an object property as string or output a string return by a function.

Syntax:

<!--##=...##-->

Note the "=" symbol immediately after the start tag. This is analogous to <%= ... %> in ASP.

The function can be a built-in system function or an user function defined in user code file (see Using User Code). You can refer to the System Functions list for functions that you can call or override.



Format 1 (accessing object property):

Syntax:

<!--##=Object.Property##-->

Example

<!--##=PROJ.ProjName##-->

This line will write the project name in the output file.

 

Format 2 (access a function):

Syntax:
<!--##=Function##-->

Example

<!--##
' This is a script block
Function MyFunction
    MyFunction = "This is my custom function"
End Function
##-->

<!--##=MyFunction##-->

This line calls the function "MyFunction" and write the string returned by the function in the output file. In real cases, the returned string is the code you want to generate.

 

4. Function Block with Indentation

Syntax:

<!--##~...##-->


Note the "~" symbol immediately after the start tag. This function is same as function block above except that output block will be indented with the space before the block.

Example

If you have 4 spaces before the following tag:
    <!--##~Script##-->

and the Script Block will output the following block of codes:

' Field UserID
sTmp = Trim(x_UserID)
If Trim(sTmp) & "x" = "x" Then sTmp = Null
rs("UserID") = sTmp

The final output will become the following. Note that all lines are indented by the specific amount of space before the tag:

    ' Field UserID
    sTmp = Trim(x_UserID)
    If Trim(sTmp) & "x" = "x" Then sTmp = Null
    rs("UserID") = sTmp

 

5. Language Block

Syntax:

<!--##@phrase##-->


Note the "@" symbol immediately after the start tag. This tag translate the phrase directly from lang.xml.

Example

<!--##@BackToList##-->

This line outputs the phrase "BackToList" as defined in the lang.xml. If the lang.xml file contain the node:

<phrase id="BackToList" value="Back to List"/>

The line write "Back to List" to the output file.

This tag is equivalent to:

<!--##=LANG.Phrase("BackToList")##--> (See Template Object Propeties)


 

6. Dynamic Language Block

Syntax:

<!--##?variable##-->


Note the "?" symbol immediately after the start tag. This tag evaluates the content as function or variable before translate from lang.xml

Example

<!--##?TABLE.TblType##-->

If TABLE.TblType returns "TABLE", the above tag will be equivalent to:

<!--##@TABLE##-->

or

<!--##=LANG.Phrase(TABLE.TblType)##--> (See Template Object Propeties)

If the lang.xml file contain the node:

<phrase id="Table" value="TABLE"/>

Then the line writes "TABLE" to the output file. (Note the phrase id in lang.xml is case-insensitive.)


 

Also See:

Template Object Propeties
System Functions
Using User Code

 

 
 ©2007-2011 e.World Technology Ltd. All rights reserved.