You are on page 1of 3

Freemarker Directives Cheat Sheet

by Suniahk (suniahk) via cheatography.com/19837/cs/2789/

Built In References - Strings Built In References - Strings (cont) Built In References - Strings (cont)

boolean Converts string to boolean js_string Escapes the string for remove​_end Same as remove​_be​gin​ning,
(true, false) Javascript String Literals ing except fromt he ending

cap_first Capita​lizes first word of string json_s​tring Escapes the string for JSON rtf Rich Text Format

capitalize Capita​lizes every word in string String Literals split Split a string at each substring
properly keep_after Returns all text after substring, (subst​ring)
(subst​ring, not including substring
chop_l​ine​bre Removes line-break from end of starts​_with Same as ends_with, but for
flags=​"​")
ak string string beginning
keep_b​efore Returns all text before
contains Checks if string contains string Takes a multi-​value variable and
(subst​ring) substring (subst​ring, substring, not including returns just the string parts
flags=​"​") substring
date, time, Converts string to substring Depric​ated, use string​[x..y]
datetime date/t​ime​/da​tetime based on last_i​ndex_of Returns the index of the last
trim Removes leading and trailing
*_format (subst​ring) occurance of substring
whitespace
left_pad (x, Returns the string with
ends_with Checks if string ends with uncap_​first The opposite of cap_first
(subst​ring) substring sepera​tor​=" [seper​ator] prepended up to a
") maximum length upper_case Opposite of lower_case
ensure​_en​ds Returns string with substring
length The number of characters in url URL Character escaping
_with appended if not already there
the string url_path Same as url but doesn't escape
(subst​ring)
lower_case Returns string in all lower case slashes
ensure​_st​art​ Same as ensure​_en​ds_​with, but
s_with prepended matches Regex Pattern checker word_list Returns a sequence of all words
(subst​ring) in a string
number The string as a number
groups[x] Returns the returns the regex xhtml Same as html, but for xhtml
replace Returns all occurances of
group from the matches method escaping
(subst​ring, substring with replace
if it exists xml Same as hxtml, but difference
replace)
html Returns the string with html code for '
right_pad (x, Same as left_pad, but
characters parsed to sepera​tor​=" appended instead
ampersand codes ") Built In References - Numbers

index_of Returns the index of the remove​_be​gin Returns string with substring abs Absolute Value
(subst​ring) requested substring in string ning removed from the beginning
c Num to String without formatting
j_string Escapes the string for Java (subst​ring)
is_inf​inite True if number is floating point
String Literals
infinite

is_nan True if number is NaN

By Suniahk (suniahk) Published 6th November, 2014. Sponsored by CrosswordCheats.com


cheatography.com/suniahk/ Last updated 6th November, 2014. Learn to solve cryptic crosswords!
Page 1 of 3. http://crosswordcheats.com
Freemarker Directives Cheat Sheet
by Suniahk (suniahk) via cheatography.com/19837/cs/2789/

Built In References - Numbers (cont) Built In References - Booleans Built In References - Nodes (XML)

round, floor, Rounds to closest, lowest, and c Boolean to String for computer ancest​ors​(n Returns a sequence of nodes
ceiling highest, respec​tively languages ame) ancestors. Starts with immediate
parent and ends with root.
string.format Num to String with optional string​("s Boolean to String with
Should be filtered with name
formatting (format can be t​rin​g1", human-​rea​dable flags. Provided as
number, currency, percent, or "​str​ing​2" "​str​ing​1" for true and "​str​ing​2" for children Returns a sequence of all child
computer) ) false nodes

node_name Returns the node name


Built In References - Date/t​ime​/da​te-time Built In References - Sequences (directive invoked when node is
"​vis​ite​d")
date Returns date only from a chunk(x, Splits sequence into multiple
datetime value (Only use if filler​=null) sequences of size x. Last chunk node_n​ame​ Returns namespace string of
variable is proble​matic) space node
first Returns the first element of the
time Returns time only from a sequence node_type Returns a string with the node
datetime value (Only use if type
join(s​epe​rat Concat​onates sequence
variable is proble​matic) parent Returns the immediate parent
or) elements with seperator in
datetime Returns date and time from a between node
datetime value (Only use if root Returns the root node
last Returns the last element in the
variable is proble​matic)
sequence
(date/​tim​e/d​a Marks a date-like value with reverse Returns the sequence in reverse Common Flags
te​tim​e)_​if_​un specified missing subtype order i Case Insens​itive (eg. x==X)
known
seq_co​nta​in Returns true if the squence
f First Only (Only apply to first occurance)
iso_... Converts date-like value to s​(ne​edle) contains needle
specified iso format. Depricated r Substring is regex
seq_in​dex​_ Same as contains, but returns
in favour of _format settings m Multi-line mode for regex
of​(ne​edle) the index of the first element
string.format Converts date-like object to s Enables dot-all mode for regex (. is
seq_la​st_​ind​ex_​of(​needle)
string. See freemarker manual wildcard)
for formats size
c Allows whitespace and comments in regex
sort

sort_by Built In References - Hashes

Keys A sequence with all the hash keys

Values A sequence with all the hash values

By Suniahk (suniahk) Published 6th November, 2014. Sponsored by CrosswordCheats.com


cheatography.com/suniahk/ Last updated 6th November, 2014. Learn to solve cryptic crosswords!
Page 2 of 3. http://crosswordcheats.com
Freemarker Directives Cheat Sheet
by Suniahk (suniahk) via cheatography.com/19837/cs/2789/

Rarely Used Built-Ins Template Language Quick Reference (cont) Template Language Quick Reference (cont)

byte, Converts numbers to other types compress Removes all but one newline local Like assign, but creates local
double, of numbers character between lines variables within macros or
float, int, functions
escape x <pr​e> tag for freemarker code
long, short
as x? macro/​nes​te Macro outputs a block of user-
eval Evaluate a string as an FTL [escape d​/return d​efined code which wraps
expression type] nested (optio​nally, otherwise

has_co​ntent Returns true if variable exists flush Forces generated output to be just outputs the code). return
works as a break
and isn't empty, false otherwise written. 99% of the time is not

interpret Returns the value of a string neccessary noparse <pr​e> tag for ftl

interp​reted as FTL code. Sort of ftl Tells programs that file is an ftl nt No trim. Disables whitespace
like a function file. Takes optional parameters stripping

is_...[​type] Checks if variable is of type found on the docs page setting Modifies parse settings. View
[type]. See docs for full list functi​on/​re Similar to a macro, except returns name=value full list in the docs page
turn a specific value as denoted by
namespace Returns macro or function stop Per ftl docs: an emergency
namespace, if any return [reason] brake. Don't use in normal
global Makes a global variable. Variable situat​ions. Returns reason if set
new Creates a variable of type class.
will be exposed as if at data-model
Usage is var = "​FQD​N"? switch​/ca​se/​ A regular switch block
level
n​ew(​opt​ions) def​aul​t/break‐

number​_to​_[ Converts a number to if/els​eif​/els Creates an if/els​eif​/else block t, lt, rt Trim, left trim, right trim. Ignores
e
d​ate​/ti​me/​da date/t​ime​/da​tetime, using the whitespace based on tag
t​etime] number of seconds since epoch import Imports the library at location path position used
path as for use in the current ftl file visit/​rec​urs​e/ Used for parsing trees, usually
Template Language Quick Reference hash f​allback XML. See the ftl docs for full info
include Includes the file at location path
assign name=value [in Creates a variable
path for use in current document
namesp​ace​hash] called name
list foreach loop
attemp​t/r​ecover try/catch
sequence
as item

By Suniahk (suniahk) Published 6th November, 2014. Sponsored by CrosswordCheats.com


cheatography.com/suniahk/ Last updated 6th November, 2014. Learn to solve cryptic crosswords!
Page 3 of 3. http://crosswordcheats.com

You might also like