Script
How to Format Rules with JavaScript Expressions
JavaScript expressions can be used with the following syntax:
In newer versions of Squidex, the user interface has been improved and custom input fields have been introduced which allows selection of the syntax and adds the necessary prefix automatically.
Basic Syntax
The scripting engine supports almost all ES6 features with a few restrictions.
Therefore, it is best to use the Javascript template string syntax and just reference properties directly:
Special Functions
Squidex provides a set of general helper functions for scripting and rule formatting.
A value list can be found in the documentation concerning scripting helper methods here:
Scripting Helper MethodsAdditionally, there are also methods which are only available for rule formatting.
contentAction()
The status of the content, when the event is a content event.
Otherwise null
.
contentUrl()
The URL to the content in the Management UI, when the event is a content event. Otherwise null
.
assetContentUrl
The URL to download the asset, when the event is an asset event.
Otherwise null
.
This URL does not include the app name and is therefore not recommended.
assetContentAppUrl
The URL to download the asset by ID, when the event is an asset event.
Otherwise null
.
assetContentSlugUrl
The URL to download the asset by slug, when the event is an asset event.
Otherwise null
.
complete(value)
If you use an asynchronous operation, just like getAssets
you have to tell the script engine, which value should be returned. Therefore you have call complete(value
) with the result value. If you do not call this method, the result of the last statement is used.
Examples
Resolve References
You can use scripting to resolve references. You must pass over an array of content IDs and a callback (that is invoked) with the resulting list of content items.
Or a single reference:
Resolve References
You can use scripting to resolve assets. You have to pass over an array of asset IDs and a callback (that is invoked) with the resulting list of assets.
Or a single asset:
Conditional Formatting
You can use if-statements and other JavaScript language features for conditional formatting.
In the following example, different payloads have been created, depending on the asset size:
Last updated