Expressions
SiteGlow has its own expression evaluator that will recognize typical boolean, numeric and string expressions. The expressions can use standard operators (e.g. +, -, /, *), some key functions (boolean, numeric, date and string) and, most importantly, can reference any ST attribute defined in the current scope (e.g. pub, site, units). What follows is a list of the operators, functions and identifiers accepted in SiteGlow expressions:
Operators
| Operators | Notes | Example | Result |
|---|---|---|---|
| + - * / % ( ) | Arithmetic operators. Plus sign also concatenates strings. |
((3 + 4 - 1) / 5) * 10 | 12 |
| true false ! && || | Logical operators | (true && false) || (true && !true) | false |
| == != < <= > >= | Comparison operators | (1 == 2) || (1 < 2) || (1 > 2) | true |
| "..." | String Delimiters | "Test" + "ing" | Testing |
| "...%[exp]%..." | Inline Expression. Everything within brackets will be parsed as an expression and its string representation will be substituted into the string. | "The result is %[2+3]%" | "The result is 5" |
| #...# | Date delimiters. Use format #dd/MM/yyyy# or #dd/MM/yyy hh:mm:ss# |
#31/12/2007 23:59:59# > #31/12/2006# | true |
| object.Property | 'Dot' operator used to access object properties or dictionary entries. | pub.Title units.Text1 |
(value of property) |
| object[indexOrKey] | Brackets used to access array/list elements (by position) or dictionary entries (by key). | list[0] dictionary["key"] |
(referenced elemnent) |
| function(...) | Parentheses used to call functions (see below). Can contain comma-separated parameters. | Contains("abcde", "bcd") | true |
Identifiers
Identifiers are reserved words that can be used in SiteGlow expressions to access ST attributes, system values or fixed constants. For example, they can be used to access the current date and time, or the Title of the current Publication.
| Identifier | Notes | Example | Result |
|---|---|---|---|
| pb | Represents the ST property bag, which contains all attributes defined in the current scope. | pb.AttributeName | (value of attribute) |
| user isAuthenticated domain site pub content units |
Standart SiteGlow attributes in the ST property bag. More direct than using pb above. |
user.Username pub.Title units.Text1 |
(value of attribute) |
| ChCr ChLf ChCrLf |
Represents the special Carriage and LineFeed ASCII characters. | "Line 1" + ChCrLf + "Line 2" | Line1 Line2 |
| Now UtcNow |
Returns a DateTime object with the current date and time, in either local or UTC (Universal Time Coordinate) timezones. |
UtcNow > #01/01/2005# | true |
| Null DbNull |
Represents a null or undefined value. Rarely used. | pub.Title == Null | false |
Functions
Functions are reserved words that can be used in SiteGlow expressions to call external code that will return a result given some parameters passed to it. For example, functions can determine whether a variable is emtpy, return the length of a string, replace a string by another string, or return a date formatted in a certain way.
| Function | Notes | Example | Result |
|---|---|---|---|
| IsNull(value) | Returns true if value is null. False otherwise. |
IsNull("test") IsNull(Null) |
false true |
| IsNullOrEmpty(s) | Returns true if string s is null or empty. False otherwise. |
IsNullOrEmpty("test") IsNullOrEmpty("") IsNullOrEmpty(Null) |
false true true |
| If(condition, valueIfTrue, valueIfFalse) | Returns one of two values depending on a test condition. | "The list is " + If(5 > 3,"large","small") | The list is large |
| Contains(s, match) | Returns true if s is contains match. False otherwise. Case insensitive. |
Contains("abcdef","bcd") | true |
| ContainsExactly(s, match) | Same as Contains above, but with case-sensitive search. |
Contains("abcdef","BCD") ContainsExactly("abcdef","BCD") |
true false |
| Length(s) | Returns the number of characters in string s. |
Length("test") | 4 |
| Chr(i) | Returns the ASCII character that corresponds to the decimal integer i. |
"This is the tilde character: " + Chr(126) | This is the tilde character: ˜ |
| Trim(s) TrimStart(s) TrimEnd(s) |
Trims spaces from respective ends of the string s. |
Trim(" test ") TrimStart(" test") TrimEnd("test ") |
test test test |
| ToLower(s) ToUpper(s) |
Return the lowercase or uppercase version of the string s. |
ToLower("The Test") ToUpper("The Test") |
the test THE TEST test |
| Replace(s, match, replace) | Replaces within string match with string replace. |
Replace("A good effort", "good", "great") | A great effort |
| Substring(s, startIndex, length) | Returns a substring from string s. The substring will be length characters long and will start at character position startIndex , where the first character is position 0. |
Substring("A good effort", 0, 6) Substring("A good effort", 2, 4) |
A good good |
| Split(s, delimiter) | Returns a string array with the parts thar result from splitting the string s every time the string delimiter is encountered. |
Split("A good effort", " ").Length Split("Item1|Item2|Item3", "|")[0] |
3 Item1 |
| Date(year, month, day) | Returns a DateTime object given a year, month and day integers. |
Date(2007,12,31) > Date(1999,1,1) | true |
| Year(date) Month(date) Day(date) |
Returns the year, month and day integers of a given date object. |
Year(Date(2007,12,31)) Month(Date(2007,12,31)) Day(Date(2007,12,31)) |
2007 12 31 |
| Format(o, format) | Returns the string that results from applying the format string to the object o. Use only for DateTime and numeric objects. More information on format strings can be found here. |
Format(123,"#.00") Format(Date(2007,12,31), "yyyy-MM-dd") |
123.00 2007-12-31 |