Jelly - the util taglib
Part 11 in an ongoing series about Jelly...
Here is a simple Jelly script that shows some of the Utility Tag Library in action.
Let's look at it in a bit more detail:
2:<jelly xmlns="jelly:core" xmlns:u="jelly:util" trim="no">
3:
4: <u:available uri="core1.jelly">
5: Found core1.jelly
6: <u:loadText var="script" file="core1.jelly" />
7: script contents are:
8: ${script}
9: </u:available>
10:
11: <u:tokenize var="cities" delim=",">
12: Sydney,
13: San Francisco,
14: Wellington,
15: Beijing
16: </u:tokenize>
17:
18: <forEach var="city" items="${cities}" trim="no">
19: Found '${city.trim()}'
20: </forEach>
21:
22:</jelly>
Line 9 uses the available tag to test for the availability of a resource (file) called core1.jelly in the same location as the script. If that resource is found, the body of the available tag is executed.
Line 11 uses the loadText tag to load the contents of a text file into a variable, in this example the variable is script.
Line 16 uses the tokenize tag to split the text of it's body using a comma as the delimiter.