$CMS_VALUE(...)$
Using $CMS_VALUE(...)$
In order for the contents of variables, input components or functional results to be visible in template sets they must be output within the templates. For example, in order for the content of an input component to be visible in the browser the content of the input component must be output in the HTML area of the template within the HTML template set (“HTML” tab). These contents can be accessed in templates using the $CMS_VALUE(...)$ instruction. In addition, within the instruction, expressions (see also expressions) can be evaluated and methods (see also Methods) can also be used. The usable expressions and methods depend on the type of variable, i.e. one input component returns a variable of the type Set, another input component returns a variable of the type string (see also Forms).
Here the name of the variable to be referenced is given within the brackets, in the example the name of the input component. If, instead of the variable itself, an attribute of the variable is to be integrated on the page, the name of the attribute, separated by a dot (full stop), must be given behind the variable name.
Syntax of $CMS_VALUE(...)$
The following syntax must be adhered to when using $CMS_VALUE(...)$:
$CMS_VALUE(VARIABLE)$
or
$CMS_VALUE(CONSTANT)$
or
$CMS_VALUE(EXPRESSION)$
The simplest form of $CMS_VALUE(...)$ outputs the value of a variable. However, more complex expressions can also be used within the brackets (...):
Example: Combination with "+" operator:
$CMS_VALUE(myNumber + 2)$
Example: Combination with dot notation:
$CMS_VALUE(myValue.toString)$
If a variable is not defined or null, an appropriate error message will be output in the log for debugging purposes, e.g. Undefined field or Undefined variable. You can check if a variable is null (method .isNull()) or empty (method .isEmpty()) to prevent error messages, for example $CMS_IF(!VARIABLE.isNull)$ $CMS_VALUE(VARIABLE)$ $CMS_END_IF$ The options to check if a variable has been set via the function isSet(...), or to define a default value by means of default (e.g. $CMS_VALUE(VARIABLE, default:"Default value")$, see below), should be used with care since error messages will be suppressed in this case. This will make debugging more difficult. In the case of isSet the value may be output on the generated page unintentionally. |
Within a $ CMS_VALUE (...) $ statement, multiple parameters (variables, constants, expressions), are passed comma separated, for example, when defining a default value.
Syntax (Definition of a default value):
$CMS_VALUE(OBJECT1, default:OBJECT2)$
Example (Definition of a default value):
$CMS_VALUE(VARIABLENAME,default:"--VALUE NOT SET--")$
In the example, if the variable VARIABLENAME is not defined, --VALUE NOT SET-- is output.
Examples of $CMS_VALUE(...)$
Several examples of use of the instruction within templates are shown in the following. The examples are intended to clearly show the specific effect of the instruction and provide help for the template developer when creating their own templates.
The examples displayed here must be adjusted for use within a project! For example, variable names must be changed to the specific variable names of the project in which the instruction is to be used. |
1st Example: Method invocation
Code example:
$CMS_SET(characterstring, "A character string with many letters")$
$CMS_VALUE(characterstring.contains("with"))$
Description:
In the given example, a variable characterstring is defined with a character string. The method contains, which can be applied to a string, is used to check whether the sub-character string with is contained in the character string A character string with many letters .
Output:
true
2nd Example: Constant output
Code example:
$CMS_VALUE("CONSTANT")$
Description:
In the example the constant CONSTANT is output.
Output:
CONSTANT
3rd Example: Use of further expressions
More examples for using (arithmetical, comparative and logical) expressions:
$CMS_VALUE(6 * 7)$
Outputs the number “42”.
$CMS_VALUE("1" == "1")$
Outputs the value “true”.
$CMS_VALUE(true || false)$
Outputs the value “true”.