[CS2] Template Functions
There are a number of functions you can use inside the templating language. Functions must appear inside of braces.
{{ upperCaseFirstLetter('jim') }}
The following is a complete list of available functions.
Function | Description | Example | Output |
absoluteValue(number) | Returns the absolute value of a number. | absoluteValue(2) absoluteValue(-2) |
2 2 |
ceiling(decimal) | Returns the largest integer from a decimal number. | ceiling(4.2) | 5 |
centerMeX() |
Returns the left corner position needed to center the current layer within the design. Can also take a parameter to center itself inside another layer. | centerMeX() centerMeX('layer name') |
75 125 |
centerMeY() |
Returns the top corner position needed to center the current layer within the design. Can also take a parameter to center itself inside another layer. |
centerMeY() centerMeY('layer name') |
75 125 |
cite() | Returns the calculated value of a Dataset cell or a Layer property for the same row or layer. Only useable in the Dataset and Layer fields. Not compatible with fields that utilize the random() function. Click the label name for a Layer property to copy the correct cite() call to the clipboard. | cite('column') cite('width') |
5 675 |
cosine(number) | Returns the cosine of the number. | cosine(0) | 1 |
currentLayerName() | Returns the name of the current layer being processed. | currentLayerName() | Battle Icon |
endsWith(str, end) | Returns true if the last characters of str match end. | endsWith('Fred','ed') endsWith('Fred','er') |
true false |
floor(decimal) | Returns the smallest integer from a decimal number. | floor(4.2) | 4 |
format(pattern, val1, val2, val3) | Returns a formatted string using a replacement pattern. Use %s for a string variable and %d for a digit and %.2f for a number with 2 places after a decimal. For more detailed information on what you can do with this, check out this external documentation. |
format('The %s costs $%.2f.', 'tea', 1.991) | The tea costs $1.99. |
get(variable) | Returns a variable set earlier using the set() function. | get('foo') | bar |
inList(test, val1, val2, val3) | Returns true if test is equal to any of the values. Accepts any number of parameters. | inList('red', 'green', 'blue', 'black') inList('red', 'green', 'red', 'black') |
false true |
inText(str, inc) |
Returns true if inc is found anywhere inside of str. | inText('Fred', 'red') inText('Fred', 'foo') |
true false |
join(sep, str1, str2, str3) | Concatenates all of the str with the sep. Accepts any number of parameters. | join('//', 'green', 'red', 'yellow') | green//red//yellow |
layerBottom(name) | Returns the Y position of the bottom of the named layer. Also see $previous below. | layerBottom('layer name') | 200 |
layerHeight(name) | Returns the height of the named layer. Also see $previous below. | layerHeight('layer name') | 100 |
layerLeft(name) | Returns the X position of the left-side of the named layer. Also see $previous below. | layerLeft('layer name') | 40 |
layerRight(name) | Returns the X position of the right-side of the named layer. Also see $previous below. | layerRight('layer name') | 70 |
layerTop(name) | Returns the Y position of the top of the named layer. Also see $previous below. | layerTop('layer name') | 25 |
layerWidth(name) | Returns the width of the named layer. Also see $previous below. | layerWidth('layer name') | 300 |
lowerCase(string) | Lower cases a string. | lowerCase('aBcDeF') | abcdef |
length(string) | Returns the number of characters in a string. | length('crafter') | 7 |
max(number, max) | Returns a number equal to or lower than the max. | max(5,3) max(1,3) |
3 1 |
maxOfAll(num1, num2, num3) | Returns the largest number from the input list. Accepts any number of arguments. | maxOfAll(1,2,3) maxOfAll(112, 54, 78) |
3 112 |
min(number, min) | Returns a number equal to or higher than the min. | min(5,3) min(1,3) |
5 3 |
minOfAll(num1, num2, num3) | Returns the smallest number from the input list. Accepts any number of arguments. | minOfAll(1,2,3) minOfAll(112, 54, 78) |
1 54 |
plural(str, num, inclusive) | Allows you to create pluralized text in an easy manner based upon what the value of the integer is. |
plural('test') plural('test', 0) plural('test', 1) plural('test', 5) plural('test', 1, true) plural('test', 5, true) plural('蘋果', 2, true) |
tests |
pi | A constant holding the value of PI. | pi | 3.14159265359 |
random(min, max) | Returns a random integer between two integers (inclusive). | randint(1,10) randint(1,10) randint(1,10) |
3 1 9 |
range(number, min, max) | Returns a number between min and max (inclusive). | range(1,3,5) range(3,1,5) range(5,1,3) |
3 3 3 |
renderVersion(detail) | Returns a version number that can be rendered onto your components to make for easier tracking of when something was generated. The version number is year down to seconds separated by dots. Detail level determines how many parts of the version to show and ranges from 1 to 6. | renderVersion() renderVersion(1) renderVersion(2) renderVersion(3) renderVersion(4) renderVersion(5) renderVersion(6) |
2022.3.21 2022 2022.3 2022.3.21 2022.3.21.19 2022.3.21.19.4 2022.3.21.19.4.17 |
repeat(string, number) | Repeats some text a certain number of times. Is often used for repeating an icon a certain number of times. | repeat('X',4) | XXXX |
replace(string, find, replace) | Replaces 1 string with another inside a third string. | replace('Text','x', 'X') replace('Text','', ' - ') replace('Requires 3 water.', 'water', '<water/>') |
TeXt T - e - x - t Requires 3 <water/>. |
round(decimal) | Returns the smallest integer from a decimal number if the remainder is less than 5 or the highest when it's 5 or above. | round(4.2) | 4 |
rows() | Returns an collection of all enumerated rows in the dataset. When used in a loop you can access cell values of each row. | {% for item in rows() %} {{item.name}} {% endfor %} |
Card_1 Card_2 Card_3 |
set(variable, value) | Set a variable for retrieval later. | set('foo','bar') | |
setGet(variable, value) | Set a variable for retrieval later, but also output it now. | setGet('foo','bar') | bar |
sine(number) | Returns the sine of the number. | sine(0) | 0 |
split(string, position, delimiter) | Splits a string based upon a delimiter. The delimiter defaults to '-'. By default the first value position (0) will be returned. You can specify another value position optionally. | split('red-green-blue') split('red-green-blue',1) split('red_green_blue',1,'_') |
red green green |
squareRoot(number) | Returns the square root of the number. | squareRoot(4) | 2 |
startsWith(str, start) | Returns true if str begins with start. | startsWith('Food','Foo') startsWith('Food','Bar') |
true false |
substring(str, start, length) | Returns a portion of a string. | substring('Component', 1, 2) substring('Component', 0, 4) |
om Comp |
upperCase(string) | Upper cases a string. | upperCase('aBcDeF') | ABCDEF |
upperCaseFirstLetter(string) | Upper cases the first letter in a string. | upperCaseFirstLetter('aBcDeF') | ABcDeF |
upperCaseEachWord(string) | Upper cases the first letter in each word in the string. | upperCaseEachWord('component studio') | Component Studio |
There are also a number of functions provided just for dealing with Advanced Tables.
$previous
There is a special layer called $previous that can be used by layerBottom(), layerTop(), layerWidth(), layerHeight(), layerLeft(), and layerRight(). This layer points to the previously rendered layer (not layer group). You'd use it like this:
{{ layerBottom('$previous') }}
This is useful, for example, to stack multiple variable-height text layers together, especially if some of them are conditionally rendered. To make this work the text layers will usually have their "Height Boundary" property set to "used".