JavaScript snippets
Support for dynamic content (JavaScript snippets)
The system allows inserting dynamic content using JavaScript snippets. They can be used in the following places:
in components Formatted content (TextContent),
in components Label,
in properties Label available in other components.
Functionality does not include the component Formatted content (TextContent) placed in the Footer area.
JavaScript snippet format
Snippets have the form:
<?js: return "value"; /** sample JS code returning a value */ ?>The snippet content must always return a value (e.g. a string).
Usage examples
1. Returning a value depending on a form field
The snippet below will return the text "m1. " only when the field with the identifier GesTextField1 has been filled:
<?js: return getValue("GesTextField1") ? "m1. " : ""; ?>2. Handling default and custom value (session variables)
In the example below, if the variable etykietaWlasna is empty or has the value null, the value from etykietaDomyslna.
Both values are available as session variables:
3. Snippet with HTML formatting
Depending on the value of the field channel the returned content containing HTML is generated dynamically:
Available JavaScript methods
Within snippets you can use the methods described in the section:
Expression language for defining conditions
This allows, among other things, referencing field values, comparisons, checking for empty values, etc.
Important note about identifiers
In snippet content we do not prefix component identifiers or variable names with the symbol @.
Correct example:
Incorrect example:
Last updated
Was this helpful?
