Skip to content

Expression

This plugin assists with exposing custom expressions to Player content. See ExpressionEvaluator for the runtime engine these handlers are registered with.

Define handlers for the expressions you wish to add:

import {
ExpressionHandler,
ExpressionContext,
} from "@player-ui/expression-plugin";
const customExpressionHandler: ExpressionHandler = (ctx: ExpressionContext) => {
return "Hello World!";
};

Register with Player. Subsequent registrations of an expression with the same name will override previous values.

import { Player } from "@player-ui/player";
import { ExpressionPlugin } from "@player-ui/expression-plugin";
const player = new Player({
plugins: [
new ExpressionPlugin([["myCustomFunction", customExpressionHandler]]),
],
});

Any calls to myCustomFunction() within the flow will utilize the newly registered expression:

{
"asset": {
"id": "sample",
"type": "text",
"value": "@[ myCustomFunction() ]@"
}
}