Chunk Tag Filters

From Chunk Java Template Engine

(Difference between revisions)
Jump to: navigation, search
(escapexml)
Line 3: Line 3:
== alternate(<oddoutput>,<evenoutput>) ==
== alternate(<oddoutput>,<evenoutput>) ==
When tag value is odd, output <oddoutput> - when even, output <evenoutput>.
When tag value is odd, output <oddoutput> - when even, output <evenoutput>.
 +
 +
== base64 ==
 +
Base64-encode.
 +
 +
== base64decode ==
 +
Base64-decode.
== capitalize ==
== capitalize ==
Line 36: Line 42:
Alias: lc
Alias: lc
 +
 +
== md5hex ==
 +
MD5-hash (bytes encoded in two-character hex format)
 +
 +
Alias: md5
== ondefined(<output>) ==
== ondefined(<output>) ==
Line 51: Line 62:
== s/<regex>/<replace>/ ==
== s/<regex>/<replace>/ ==
Perl-style regular expression search and replace.
Perl-style regular expression search and replace.
 +
 +
== sha1hex ==
 +
SHA-1 hash (bytes encoded in two-character hex format).
 +
 +
Alias: sha1
== slice([from]:[to][:step]) ==
== slice([from]:[to][:step]) ==
Line 60: Line 76:
== title ==
== title ==
Uppercase the first letter of each word, and lowercase all other characters.  See [[#capitalize]].
Uppercase the first letter of each word, and lowercase all other characters.  See [[#capitalize]].
 +
 +
== translate ==
 +
...
 +
 +
Aliases: xlate, _
== trim ==
== trim ==

Revision as of 18:18, 18 November 2013

Chunk includes several useful filters right out of the box.

Contents

alternate(<oddoutput>,<evenoutput>)

When tag value is odd, output <oddoutput> - when even, output <evenoutput>.

base64

Base64-encode.

base64decode

Base64-decode.

capitalize

Uppercase the first letter of each word. Leave case of other characters intact. See #title.

Alias: cap

defang

Remove all but a short list of "harmless" characters - can apply to values from untrusted sources to neuter potential XSS attacks.

Alias: neuter

escapequotes

Escape single and double quotes (and backslashes) with a backslash.

Aliases: qs, quoted, quotedstring

escapexml

Convert & to &amp; and handle angle brackets, etc. See #unescapexml.

Aliases: xml, html, xmlescape

indent(<howmany>[,indentstring])

Indent each line of the input by <howmany>. Default indentstring is a space.

length

Outputs the size of a LIST or OBJECT, or the length of a STRING input.

Alias: len

lower

Convert text to lowercase. Honors Java locale settings.

Alias: lc

md5hex

MD5-hash (bytes encoded in two-character hex format)

Alias: md5

ondefined(<output>)

Output <output> when tag value is defined. Note that a tag value of null becomes the empty string, which is considered defined. To be undefined, the tag label must not exist in the tag table at all.

onempty(<output>)

For undefined or empty (ie empty string or only whitespace) values, output the given <output>, otherwise let the tag value pass through.

onmatch(/<regex/,<output>[,/<regex2>/,<output2>[,...]])[nomatch(<nomatchoutput>)]

Don't use this. Really. Use {.if (...)} {.elseIf (...)} {.else} {/if} instead. Far more readable.

reverse

Reverse a LIST.

s/<regex>/<replace>/

Perl-style regular expression search and replace.

sha1hex

SHA-1 hash (bytes encoded in two-character hex format).

Alias: sha1

slice([from]:[to][:step])

Subset a LIST using python-style slice notation.

sprintf(<format>)

The classic formatter.

title

Uppercase the first letter of each word, and lowercase all other characters. See #capitalize.

translate

...

Aliases: xlate, _

trim

Trim leading and trailing whitespace.

type

Output STRING, LIST, OBJECT, CHUNK or NULL per the tag value.

unescapexml

Unescape xml-escaped entities, including eg &#123; and &#x03BB; See #escapexml.

Aliases: unescapehtml, unxml, unhtml, xmlunescape

upper

Convert text to uppercase. Honors Java locale settings.

Alias: uc

urldecode

Restore %AB encoded characters. Plus character (+) is translated back to space.

urlencode

URL-Encode the value.

Alias: url

Personal tools