One of the most powerful features of StyleBook is the use of expressions. You can use StyleBooks expressions in various scenarios to compute dynamic values. The example below shows an expression to concatenate a parameter value with a literal string.

Example:

\$parameters.appname + “-mon”

This expression retrieves the parameter named appname, and concatenates it with the string “-mon”.

The following types of expressions are supported:

## Arithmetic Expressions

• Substraction (-)
• Multiplication (*)
• Division (/)
• Modulo (%)

Examples:

• Adding two numbers: \$parameters.a + \$parameters.b
• Multiplying two numbers: \$parameters.a * 10
• Finding the remainder after division of one number by another:

15 % 10 results in 5

## String Expressions

• Concatenate two strings (+)

Example:

Concatenate two strings: str(“app-“) + \$parameters.appname

## List Expressions

Merges two lists (+)

Example:

• Concatenate two lists: \$parameters.external-servers + \$parameters.internal-servers

• If \$parameters.ports-1 is [80, 81] and \$parameters.port-2 is [81, 82], then \$parameters.ports-1 + \$parameters.ports-2 results as a list [80, 81, 81, 82]

## Relational Expressions

• == : Tests if two operands are equal and returns true if they are equal, else returns false.

• != : Tests if two operands are different and returns true if they are different, else returns false.

• > : Returns true if the first operand is greater than the second operand, else returns false.

• >= : Returns true if the first operand is greater than or equal to the second operand, else returns false.

• < : Returns true if the first operand is lesser than the second operand, else returns false.

• <= : Returns true if the first operand is lesser than or equal to the second operand, else returns false.

Example:

• Use of Equality operator: \$parameters.name = = “abcd”
• Use of Inequality operator: \$parameters.name != “default”
• Examples for other relational operators
• 10 > 9
• 10 >= 10
• 0 < 9
• 10 <= 9
• 10 == 10
• 10 != 1

## Logical (Boolean) Expressions

• and: The logical ‘and’ operator. If both operands are true, the result is true, else it is false.

• or: The logical ‘or’ operator. If one of the operands is true, the result is true, else it is false.

• not: The unary operator. If the operand is true, the result is false, and vice-versa.

• in: Tests whether the first argument is a substring of the second argument

• in: Tests if an item is part of a list

Note

You can type cast expressions where strings can be converted into numbers and numbers can be converted to strings. Similarly, a tcp-port can be cast to a number, and an IP address can be cast to a string.

You must use a delimiter before and after any operator. You can use the following delimiters:

• Before an operator: space, tab, comma, (, ), [, ]

• After an operator: space, tab, (, [

• For example:

• abc + def

• 100 % 10

• 10 > 9

## Expression Type Validation

StyleBook engine now allows for stronger type checking during compile time, that is, the expressions used while writing the StyleBook are validated during the import of StyleBook itself rather than while creating the configuration pack.

All references to parameters, substitutions, components, properties of components, outputs of components, user-defined variables (repeat-item, repeat-index, arguments to substitution functions,) and so on are all validated for their existence and types.

Example of Type Checks:

In the following example, the expected type of port property of lbvserver StyleBook is tcp-port. In Citrix Application Delivery Management (ADM) earlier releases, the StyleBook compiler computed the value as a string and the StyleBook was imported and executed. Now, type validations happen at compile-time (import-time). The compiler finds that string and tcp-port are not compatible types and therefore, the StyleBook compiler throws an error and fails import or migration of the StyleBook.

``````
components:
-
name: lbvserver-comp
type: ns::lbvserver
properties:
name: mylb
ipv46: 10.102.190.15
port: str("80")
servicetype: HTTP

You should now declare this as a number for the compiler to successfully compile this StyleBook.

port: 80
<!--NeedCopy-->
``````

Example of Flagging Invalid Expressions:

In earlier releases, when an invalid expression was assigned to a property name, the compiler did not detect invalid expressions and allowed the StyleBooks to be imported into Citrix ADM. Now if this StyleBook is imported to Citrix ADM, the compiler will identify such invalid expressions and flag it. As a result, the StyleBook will not be imported to Citrix ADM.

In this example, the expression assigned to name property in lb-sg-binding-comp component is:  \$components.lbvserver-comp.properties.lbvservername. However, there is no property called lbvservername in component lbvserver-comp. In earlier Citrix ADM releases, the compiler would have allowed this expression and successfully imported it. The actual failure would happen when a user wants to create a configuration pack using this StyleBook. However now, this kind of error is identified during import and the StyleBook is not imported to Citrix ADM. You must manually correct such errors and import the StyleBooks.

``````
components:
-
name: lbvserver-comp
type: ns::lbvserver
properties:
name: mylb
ipv46: 10.102.190.15
port: 80
servicetype: HTTP
-
name: sg-comp
type: ns::servicegroup
properties:
servicegroupname: mysg
servicetype: HTTP
-
name: lb-sg-binding-comp
type: ns::lbvserver_servicegroup_binding
condition: \$parameters.create-binding
properties:
name: \$components.lbvserver-comp.properties.lbvservername
servicegroupname: \$components.sg-comp.properties.servicegroupname
<!--NeedCopy-->
``````

## Indexing Lists

Items of a list can be accessed now by indexing them directly:

Expression Description
\$components.test-lbs[0] Refers to the first item in test-lbs component
\$components.test-lbs[0].properties.p1 Refers to property p1 of the first item in test-lbs component
\$components.lbcomps[0].outputs.servicegroups[1].properties.servicegroupname Refers to property servicegroupname of the second item in servicegroups component, which is an output from the first item of lbcomps component

Expressions