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
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 !
#
]]
Also, since literal # characters are very
common in HTML, we make 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
Suppose we have:
#
... bgcolor="#ffffff"
#
One would expect that the # after
bgcolor will erroneously end the hash section. (I've
used bgcolor as a specific attribute but this discussion is valid
for all foo="#bar" attributes). So we normally say:
1. # ... bgcolor="\#ffffff" #
But since some_attribute"=#value" is such a common case,
the parser also allows one to say:
All of the above (cases 1, 2, and 3) will work the same and result
in bgcolor="#xxx".
Note that in the above cases, the value of the bgcolor (or whatever)
attribute is quoted by single or double quotes. If you have the habit of
not quoting attribute values, then you always have to escape the
# contained in a hash section.
For:
## ... bgcolor=#xxx # //Note: (no single or double quotes around #xxx)
We have to say:
# ... bgcolor=\#xxx #
If all this is a bit much, then just remember to escape any # within
a hash section and you will always be OK.
Example
A simple hash section.
[[
// Note the use of an escaped \#
// to get a literal # in the output.
boolean great = true;
if (hello) {
# You are \#1 #
}
]]
You are #1
Example
A code section that prints HTML (using a hash section) from
within a Java for-loop.
[!import
import java.util.*;
]
[[
List list = Arrays.asList(
new String[] {"123", "456"} );
out.print("