Set Page info from Code
In this example we will show you how you can use the UI Builder Studio API to set the name and description of a Page.
This can be useful, for example, if you want dynamically change the Name and Description of your Page using Javascript.
In the example below, we can navigate to the page by entering the Page ID and clicking "Read Page". This was done by utilizing the Playlist API. Upon clicking the "Read Page" button, the Name and Description textboxes are automatically filled. To replace the Page name and Description, click the "Set Page Name and Description" button, the existing Page name and description will be replaced with the content from the textboxes.
Warning
Api.playlist.readPage() is asynchronous - it returns a promise. Reading Api.page.name on the next line without awaiting it returns the values of the previously selected page.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | |
Info
Selecting the page in the playlist is applied on a short debounce (100 ms) and the page payload then loads asynchronously. If the textboxes still show the previous page's values, the selection had not been applied yet when displayPage() ran - read the values from a later user action instead.
Page properties you can set
The same mechanism exposes the following properties on Api.page:
| Property | Notes |
|---|---|
name |
Any string. |
description |
Any string. |
num |
The page number. Digits only. |
channel |
The channel of the page. |
readOnly |
Boolean. |
color |
A hex colour, #RRGGBB or #RRGGBBAA. Throws for any other format. |
Warning
Assigning a value of the wrong type is silently ignored: a non-string assigned to name, description, num or channel does nothing, and so does a num that is not digits only. Only color raises an error. Convert the value yourself, for example Api.page.num = String(myNumberInput.value).
We can also set the page name and description on the onChange function of fields in the user interface. When the operator saves the page, these values will be set as the page name and description, allowing for a fast and automated workflow for the operator.
In the example below, we prefix the page name with an identifier, indicating to the operator the type of graphic, and the value from the "title" field.
1 2 3 4 5 6 7 8 9 | |