A collection of cool hidden and not so hidden features, to be used as a quick reference so that you turn coffee into code much faster :)
- Namespace
- Template
- Parameters
- Parameter Types
- Call
- Variables
- Conditionals
- Loops
- Special Characters
- Functions
{namespace foo}
/**
*
*/
{template .hello}
Hello world
{/template}
/**
*
*/
{template .hello}
{@param name: string}
Hello {$name}
{/template}
/**
*
*/
{template .hello}
{@param? name: string}
Hello {$name}
{/template}
string
bool
int
float
number
any
?
null
html
list<Type> // List
map<KeyType, ValueType> // Map
[a:KeyType, b:ValueType] // Record
Type1|Type2 // Union
{call .hello}
{param name: 'Jon' /}
{/call}
{call .hello}
{param name: $name /}
{param lastName: $lastName /}
{/call}
{call .hello data="all" /}
{let $name: 'Jon' /}
{let $names: [
['first': 'Jon', 'last': 'Snow'],
['first': 'Arya', 'last': 'Stark']
] /}
{let $name kind="text"}
Jon
{/let}
{let $name kind="html"}
<p>Jon</p>
{/let}
{if $name}
Hello {$name}
{/if}
{if $name and $lastName}
Hello {$name} {$lastName}
{/if}
{if not $name}
Hello there
{/if}
{if $name}
Hello {$name}
{else}
Hello there
{/if}
{if $gender == 'Male'}
Hello Sir
{elseif $gender == 'Female'}
Hello Madam
{/if}
{switch $gender}
{case 'Male'}
Hello Sir
{case 'Female'}
Hello Madam
{default}
Hello Human
{/switch}
Hello {$name ?: 'there'}
{$name ? 'Hello {$name}' : 'Hello there'}
{foreach $name in $names}
Hello {$name}
{/foreach}
{foreach $name in $names}
Hello {$name}
{ifempty}
Hello there
{/foreach}
{literal}
<pre>
function() {
console.log('Hello');
}
</pre>
{/literal}
{sp} // space
{nil} // empty string
{\n} // newline
{\r} // carriage return
{\t} // tab
{lb} // left brace
{rb} // right brace
{isNonnull(value)}
{strContains(string, subString)}
{ceiling(number)}
{floor(number)}
{max(number, number)}
{min(number, number)}
{randomInt(number)}
{round(number)}
{index($var)}
{isFirst($var)}
{isLast($var)}
{length(list)}
{augmentMap(map1, map2)}
{keys(map)}