Hash

Lots of out.println(..) in java code are hard to write, maintain and read. A hash section is a simple way to output HTML/text from within java code without having to use out.println() statements.

Syntax

Hash sections can appear anywhere in a java code section.
#
..text/html here (can be any number of lines)..
#

Tag-Escape

This is only a concern inside a code section (which is the only place a hash section can exist). Any other # is always just a literal # (so you can use these without worry in CSS sections etc., as long as those sections are not within a code section).

To prevent the tag from being recognized, this tag can be escaped by prefixing the start tag with a backslash: \#

The parser is aware of valid java statements and java code. Therefore any # appearing inside java strings is ignored. For example:

[[
String foo = "abc#123";
]]
The # in abc#123 does not start a hash section. (so java code works with no modifications inside a code section).

The following is a valid hash section (and note, not valid java code so there is no overlap between a hash section and valid java code).

[[
String foo = "abc#123";
# 
Hello World ! 
#
]]

Since literal # characters are very common in HTML, the parser makes a special exception to the tag-escape rule. You don't have to know this rule, just use normal escapes when needed, but if you want to save some typing, see more details here

Example

A simple hash section. <html> <body> [[ // Note the use of an escaped \# // to get a literal # in the output. boolean great = true; if (great) { # You are \#1 # } ]] </body> </html> You are #1

Example

A code section that prints HTML (using a hash section) from within a Java for-loop. [!import import java.util.*; ] <html> <body> [[ List list = Arrays.asList(new String[] {"123", "456"}); out.print("<table>\n"); //or # <table> # for (int n = 0; n < list.size(); n++) { # <tr> <td>Array \#</span>[= n] : </td> <td>[= list.get(n) ]</td> </tr> # } out.print("</table>"); //or # </table> # ]] </body> </html>
Array #0 : 123
Array #1 : 456