Load Script

The Load Script allows you to store data into the Local Database, anytime a demo link is loaded up. Edit the Load Script by navigating to the Config tab, found at the top bar of the builder.

A common use case for Load Script to save values to the Local Database on load (ex: logo URLs, dummy data, today's date etc.). By returning an object of data in the Load Script code editor, you can ensure that any values needed throughout the demo are pre-loaded and ready to be referenced.

In order to reference data that is generated via the Load Script, simply ensure it is included in the object returned in the Load Script code editor.

In the example provided below, you would be able to reliably reference{{ load_script.today }} at any point in the demo.

Example

Imagine you want to showcase a flow in your demo, where a user must select a country, from a select input. In order to populate the options of the select list with country data, we can make use of Coast's load script to store a JSON array of countries. Paste the following into the code editor found in Load Script.

Load Script Countries

return {
"countries": [
  {
     "name": "The United States",
     "abbreviation": "US"
  },
  {
     "name": "Canada",
     "abbreviation": "CA"
  },
  {
     "name": "France",
     "abbreviation": "FR"
  },
  {
     "name": "China",
     "abbreviation": "CY"
  },
  {
     "name": "Brazil",
     "abbreviation": "BR"
  }
]
}

When you navigate back to the Designer, you will notice that under State, on the left panel, there is now an object called load_script, and in it, an array object, called countries.

You may now access this data, anywhere in the builder via lad_script.countries. Let's now use this data to a Select Input container. populate Add a Select Input block to a UI in your template. CLick on this input block and on the right panel, press the 🔗 button. Now, we can define the path to the options that we want to populate this select input.

We now have a functioning Select Input block in our template, that is connected to the countries array, defined in load script. Any updates or changes to this array will be immediately reflected in the Select Input.