Start page
Start page

Start page / Template development / Template syntax / Instructions / $CMS_VALUE

$CMS_VALUE(...)$

Using $CMS_VALUE(...)$

In order for the contents of variables, input components or functional results to be visible in the output channel 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 output channel (HTML tab). The editor can access these contents 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. The page in the Page Store must be updated so that the changes are visible in the GUI.

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)$

Important 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.

Definition of a default value:

$CMS_VALUE(OBJECT1, default:OBJECT2)$

Example:

$CMS_VALUE(VARIABLENAME,default:"--VALUE NOT SET--")$

In the example, if the variable VARIABLENAME is not defined, --VALUE NOT SET-- is output.

Replacements from FirstSpirit Version 4.0

From FirstSpirit Version 4.0, expressions can also be used within the $CMS_VALUE(...)$ instruction.

Examples:

"$CMS_VALUE(6 * 7)$" 

Outputs the number "42".

"$CMS_VALUE("1" == "1")$" 

Outputs the value "true".

"$CMS_VALUE(true || false)$"

Outputs the value "true".

In addition, from FirstSpirit Version 4.0 several instructions are replaced by $CMS_VALUE(...)$.
A brief overview is given in the following table:

Instruction before Version 4.0

Instruction from Version 4.0

$CMS_BODY(NAME)$

$CMS_VALUE(#global.page.body("NAME"))$

$CMS_DEREF(EXPRESSION)$

$CMS_VALUE(ref(REFERENCEEXPRESSION).EXPRESSION)$

for example:
$CMS_VALUE(ref(media:"flower").width)$

$CMS_DUMPCONTEXT()$

$CMS_VALUE(#global.dumpcontext)$

with separator (e.g.
):
$CMS_VALUE(#global.dumpcontext("SEPARATOR"))$

$CMS_LOCALVALUE(VARIABLENAME)$

$CMS_VALUE(#nav.METHOD)$

for example:
$CMS_VALUE(#nav.ref)$

  

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.

Important 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

© 2005 - 2014 e-Spirit AG | All rights reserved. | Last change: 2013-03-15