Chunk Tag Filters

From Chunk Java Template Engine

(Difference between revisions)
Jump to: navigation, search
(lpad[([,])])
(slice([from]:[to][:step]))
Line 116: Line 116:
== slice([from]:[to][:step]) ==
== slice([from]:[to][:step]) ==
-
Subset a LIST using python-style slice notation.  Negative indices and steps are supported.
+
Subset a LIST using python-style slice notation.  Negative indices and steps are supported.  Default values for <from> and <to> are the beginning and end of the list.
== sort ==
== sort ==

Revision as of 06:33, 28 June 2015

Chunk includes several useful filters right out of the box, eg {$tag|upper}.

Filters may be chained ad infinitum: {$tag|md5hex|upper}.

Contents

alternate(<evenoutput>,<oddoutput>)

When tag value is even, output <evenoutput> - when odd, output <oddoutput>. Unbraced tags are valid arguments, eg:

output {$even} and {$odd} tags:

{$i|alternate($even,$odd)}

include templates {#even} and {#odd}

{$i|alternate(+#even,+#odd)}

Alias: evenodd

base64

Base64-encode.

base64decode

Base64-decode.

capitalize

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

Alias: cap

checked(<testvalue>[,<output>])

Output checked="checked" (or <output> if specified) when tag value matches <testvalue>. Argument may be an unbraced $tag.

defang

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

Alias: neuter

default(<output>)

Output <output> if the $tag is not found in the tag table. If the tag is found, the tag value is _not_ consulted. Empty string, or a string that is completely whitespace will be output and will _not_ trigger the default output. v2.5 and up. See onempty.

escapequotes

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

Aliases: qs, quoted, quotedstring

escapexml

Convert & to &amp; and handle angle brackets, single and double quotes, etc. See unescapexml.

Aliases: xml, html, xmlescape

filter(<#xtemplate>)

Bind the tag value to {$x} and include the specified template. Provides a way to write user-contributed filters using template tag language.

get(<index>)

Output the LIST element at <index>. Zero (0) is the first element and -1 is the last element. Negative indices count back from the end of the LIST.

indent(<howmany>[,indentstring])

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

join[(<delimiter>)]

Join the LIST elements into a STRING, optionally delimited by <delimiter>.

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

lpad[(<prefix>[,<howmany>])]

If tag is defined and non-empty, output with prefix (default prefix is a single space " ").

md5hex

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

Alias: md5

ondefined(<output>)

Output <output> when tag value is defined. White space or the empty string is not considered defined for this test.

onempty(<output>)

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

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

Don't use this. Really. Use an if-block instead:

{% if (...) %} 
{% elseIf (...) %}
{% else %}
{% endif %}

Far more readable.

qcalc(<operation>)

Perform a limited set of mathematical transformations (+, -, *, /, %, ^) on an integer or floating-point (decimal) input. eg: {$tag|qcalc(+20)}. Note: a decimal point in the input will force conversion to a double float (^ is not allowed on floats). Integer division is performed on integers, floating point division on floats.

reverse

Reverse a LIST.

rpad[(<suffix>[,<howmany>])]

If tag is defined and non-empty, output with suffix (default suffix is a single space " ").

s/<regex>/<replace>/[flags]

Perl-style regular expression search and replace.

selected(<testvalue>[,<output>])

Output selected="selected" (or <output> if specified) when tag value matches <testvalue>. Argument may be an unbraced $tag.

Aliases: select, sel

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. Negative indices and steps are supported. Default values for <from> and <to> are the beginning and end of the list.

sort

Sort a LIST of homogenous, comparable items.

split[(<delimiter>|/<regexdelim>/[,<limit>])]

Transform delimited STRING into a LIST, using a simple delimiter or a /regex/ delimiter. Default delimiter is whitespace. <limit> arg is also optional.

sprintf(<format>)

The classic formatter. See [sprintf examples].

th

English ordinal suffix (1 -> 1st, 2 -> 2nd, 10 -> 10th etc.).

Alias: ordsuffix

title

Uppercase the first letter of each word, and lowercase all other characters. See capitalize. Does not follow any rules about not title-casing small words.

translate

See complete localization documentation to learn how to use this feature.

Aliases: xlate, _

trim

Trim leading and trailing whitespace.

type

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

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