2. Variables and Types

WEMscript is a statically strongly typed language. Before you can use a variable, it must be declared using the var statement, with a specific type either explicitly set or inferred from its value. Every variable is prefixed with an @ symbol. A variable's value is unknown when no value has been assigned yet.

/* Declare a boolean variable @a with an initial value of `unknownboolean` */
var @a: boolean

/* Declare a number variable @b with an initial value of `10` */
var @b := 10

/* Assign the variable @c the text "Hello" */
@c := "Hello"

The following types are available in WEMscript: boolean, concept, conceptset, datetime, duration, file, list, number, richtext, and text. These types correspond to those found in the data model of a WEM project. Additionally, there is a one-dimensional array type array<T>, where T can be any of the previously mentioned primitive types, except for array.

Properties

There is a distinction between variables and widget properties: properties are not assignable. They require a postback to update their values.

Boolean

A boolean type can be set using the keywords true, false, unknownboolean, or a WEM expression that returns a boolean type.

@a := true
@a := false
@a := unknownboolean
@a := 3.1415 <> 2.7182

Concept

The concept is a special type that can only be assigned from an existing concept variable or concept property. This is because the context (concept children and siblings) is known within a WEM project, but it is unknown within a WEM widget. For example, let's assume we have a concept property named Color.

var @a: concept

/* Assign @a the concept value that is inside the property @Color */
@a := @Color

/* This will throw an error: 'red' is an unknown concept in the context of a widget */
@a := 'red'

/* Executing concept-specific functions is allowed */
var @d := Description(@Color)
var @t := ToString(@Color)

You may be wondering how to set a concept property data field; this topic is beyond the scope of this chapter and will be explained later.

Concept set

Soon

Datetime

Soon

Duration

Soon

File

Soon

List

Soon

Number

Soon

Richtext

Soon

Text

Soon

Arrays

Last updated

Was this helpful?