Skip to content

Template Engine

Ticketeer uses an advanced template engine to allow for greater customization of the messages sent to users.

Value injection

Use the value Tag

text
{$varName}

To access array elements or objects use "." to access sub-elements:

text
 {$users.0.name}

Loops

You can insert loops:

text
{for $curName in $names}
Current Name: {$curName}
{/for}

Inside each loop, there are to magic-values @index0 (index starting with 0) and @index1 for a index starting with amp1.

text
{for $curName in $names}
Line {$@index1}: {$curName}
{/for}

Inside loops you can {break} or {continue} the loop.

Conditions (if)

You can use if-conditions:

text
{if $someVarName == "SomeValue"}
Hello World
{/if}

Shortcut: Test if a variable is null:

text
{if $someVarName}
    someVarName is set!
{/if}
{if !$someVarName}
    someVarName is not set!
{/if}

Complex logical expressions can be made using && (and), || (or) and brackets.

text
{if $someVarName && $otherVarName}
    someVarName and otherVarName are set!
{/if}
{if $someVarName || $otherVarName}
    someVarName or otherVarName are set!
{/if}
{if $someVarName || ($otherVarName && $anotherVarName)}
    Condition is true!
{/if}
{if $someVarName && !($otherVarName && $anotherVarName)}
    Condition is true!
{/if}

You can use filters on values used in comparisons.

text
{if $someArray|count > $otherArray|count}
    someArray has more items than otherArray
{/if}

Operators

OperatorDescription
==Equal
!=Not equal
>Greater than
<Less than
>=Greater than or equal
<=Less than or equal

Conditions (else)

text
{if $someVarName == "SomeValue"}
Hello World
{else}
Goodbye World
{/if}

Lists of choices:

text
{if $someVarName == "SomeValue"}
Hello World
{elseif $someVarName == "OtherValue"}
Hello Moon
{else}
Goodbye World
{/if}

Functions

Call the function and output into template

text
{sayHello msg="Joe"}

or inject the Result into the context for further processing:

text
{sayHello msg="Joe" > $out}
{$out}

Processing Exceptions:

Use !> to catch exceptions and redirect them to the scope.

{throw msg="SomeMsg" !> lastErr}

Or use !break or !continue to break/continue a loop

Filters

Call the filter with parameters (parameter-separator :):

text
{$variable|currency:2:,:.}

Use this filter inside your template

text
{$someVariable|currency}

Sections

Sections are like functions but provide the content they enclose:

text
{section name="someName"}
Some Content
{/section}
text
{section name="someName" > $out}
Some Content
{/section}

{$out}

Escaping

Use {literal}{/literal} to escape a block

text
{literal}
  {$foo} will not be parsed!
{/literal}

Comments

Use {# #} to add comments (will be stripped from output)

text
Template {# Some Comment #}
{# Some
Multiline
Comment #}

Available Functions

break

Break from a loop

INFO

Aliases: none

Argument NameArgument TypeDefault ValueDescription
----

continue

Continue in a loop

INFO

Aliases: none

Argument NameArgument TypeDefault ValueDescription
----

current_time

Returns the current time measured in the number of seconds since the Unix Epoch (January 1 1970 00:00:00 GMT)

INFO

Aliases: time, now

Argument NameArgument TypeDefault ValueDescription
----

random

Returns a random number between min and max or a random item from a list

INFO

Aliases: rand

Argument NameArgument TypeDefault ValueDescription
minnumber0Minimum number to return
maxnumber100Maximum number to return
liststring-Comma separated list

set

Set a variable in the context

INFO

Aliases: none

Argument NameArgument TypeDefault ValueDescription
namestring-Variable name
valuestring-Variable value

Available Filters

WARNING

These filters only accept non array variables

escape

Escape various Discord formatting and markdown into a plain text:

INFO

Aliases: md, clean

Argument NameArgument TypeDefault ValueDescription
----

timestamp

Format a timestamp into discord's timestamp format

INFO

Aliases: time, ts

Argument NameArgument TypeDefault ValueDescription
formatformatRFormat of the timestamp

Formats

StyleInputOutput (12-hour clock)Output (24-hour clock)
Default-November 28, 2018 9:01 AM28 November 2018 09:01
Short Timet9:01 AM09:01
Long TimeT9:01:00 AM09:01:00
Short Dated11/28/201828/11/2018
Long DateDNovember 28, 201828 November 2018
Short Date/TimefNovember 28, 2018 9:01 AM28 November 2018 09:01
Long Date/TimeFWednesday, November 28, 2018 9:01 AMWednesday, 28 November 2018 09:01
Relative TimeR3 years ago3 years ago

date

Format a timestamp into a date string

INFO

Argument NameArgument TypeDefault ValueDescription
formatformatY-m-d H:i:sFormat of the timestamp

Formats can be found here

codeblock

Wraps a variable in a codeblock

INFO

Aliases: code

Argument NameArgument TypeDefault ValueDescription
----

fallback

If a variable is empty, fallback to a default value

INFO

Aliases: else, fb

Argument NameArgument TypeDefault ValueDescription
valuestring-The value to fallback to

truncate

Limits a string to a certain length

INFO

Aliases: leng, ml, maxLength

Argument NameArgument TypeDefault ValueDescription
lengthnumber-The length to limit to
dotsstring'...'Add to the end of the truncated string

padLeft

Pads a string to the left with a certain character

INFO

Aliases: pad, lp, pl

Argument NameArgument TypeDefault ValueDescription
lengthnumber-The length to pad to
charstring-The string to pad with

padRight

Pads a string to the right with a certain character

INFO

Aliases: pr, rp

Argument NameArgument TypeDefault ValueDescription
lengthnumber-The length to pad to
charstring-The string to pad with

fixedLength

Fixes a string to a certain length

INFO

Aliases: fixed

Argument NameArgument TypeDefault ValueDescription
lengthnumber-The length to fix to

lowercase

Converts a string to lowercase

INFO

Aliases: lower, lc

Argument NameArgument TypeDefault ValueDescription
----

uppercase

Converts a string to uppercase

INFO

Aliases: upper, uc

Argument NameArgument TypeDefault ValueDescription
----

trim

Trims whitespace from the beginning and end of a string

INFO

Aliases: none

Argument NameArgument TypeDefault ValueDescription
----

split

Splits a string into an array

INFO

Aliases: explode

Argument NameArgument TypeDefault ValueDescription
separatorstring,The separator to split on

Available Array Filters

WARNING

These filters only accept array variables

count

Counts the number of items in an array

INFO

Aliases: none

Argument NameArgument TypeDefault ValueDescription
----

join

Joins an array into a string

INFO

Aliases: implode

Argument NameArgument TypeDefault ValueDescription
separatorstring,The separator to join on

has

Check if an array has a value, returns the number of matched values, input accepts comma separated values

Example:

{if $ticket.owner.roles|has:id:############1,############2,############3 > 0}

INFO

Argument NameArgument TypeDefault ValueDescription
keyOrValuestring-The key of a item in the array or the values to check
valuestring-The values to check

has_all

Check if an array has all values in a list, returns a boolean, input accepts comma separated values

Example:

{if $ticket.owner.roles|has_all:id:############1,############2,############3}

INFO

Argument NameArgument TypeDefault ValueDescription
keyOrValuestring-The key of a item in the array or the values to check
valuestring-The values to check

has_some

Check if an array has at least one value in a list, returns a boolean, input accepts comma separated values

Example:

{if $ticket.owner.roles|has_some:id:############1,############2,############3}

INFO

Aliases: includes

Argument NameArgument TypeDefault ValueDescription
keyOrValuestring-The key of a item in the array or the values to check
valuestring-The values to check

Available Sections

strip_empty_lines

Strips empty lines from a section

INFO

Aliases: strip

Argument NameArgument TypeDefault ValueDescription
----

trim

Trims whitespace from the beginning and end of a section

INFO

Aliases: none

Argument NameArgument TypeDefault ValueDescription
----

uppercase

Converts a section to uppercase

INFO

Aliases: none

Argument NameArgument TypeDefault ValueDescription
----

lowercase

Converts a section to lowercase

INFO

Aliases: none

Argument NameArgument TypeDefault ValueDescription
----