You want to share some data among multiple Klips.
You can use the Engines.DataPool object to store and retrieve data values that are shared among multiple Klips.
In this how-to article, you will find the following sections:|
Table of Contents
|
There are three functions available in the Engines.DataPool object:
To see the shared data pool working from the user's point of view:
1. Download the sample Klip and add it to Klipfolio Dashboard.
2. Duplicate the Klip through the Klip menu > Manage Klip > Duplicate.
3. In either of the Klips, go to the Klip menu > Select Area and select "Display South".
4. Observe that this selection is applied to both Klips.
Let's go through the script in the sample Klip to see how the data pool works:
1. In the onLoad() function, which is executed when the Klip is loaded (not when it is refreshed), we set up Engines.DataPool.notifyPool("area_12345", areaChange). By doing so, the data pool named "area_12345" is monitored as long as the Klip is running. Whenever its value changes, the areaChange(pool) function will be invoked.
2. In the onRefresh() function, which is executed whenever the Klip refreshes according to its refresh rate (or manually done so by the user), we set up the custom menu options through the setItemActions() function.
3. In the setItemActions() function, we set up the custom Klip menu option for "Select Area" and its submenu options for "Display North" and "Display South". Whenever the user selects "Display North", the value "north" is stored in the "area_12345" data pool; when "Display South" is selected, "south" is stored instead.
4. At this point, Engines.DataPool.notifyPool("area_12345", areaChange) from step 1 detects the change in the value of "area_12345" and invokes the areaChange(pool) function.
5. In the areaChange(pool) function, Prefs.setPref("source", Engines.DataPool.getPool("area_12345")) retrieves the stored value from the "area_12345" data pool (i.e. "north" or "south"), then stores it in the "source" preference. A Klip refresh is requested after that.
6. Back in the onRefresh() function, the "source" preference (i.e. "north" or "south") is used as part of the content source URL, whose content is displayed in the Klip according to the settings in the <style> block.
When the Klip is duplicated, both Klips will monitor the changes in the same data pool, "area_12345"; therefore, whenever the user selects "Display South" or "Display North" in either of the Klips, the same process will take place in both Klips.
In Klipfolio Dashboard Demo for Marketing, the "Traffic Sources", "Funnel" and "Site Activity" Klips share the same data pool. Try selecting a date range from one of these Klips' menus to see it reflected in all three.
An example of how the Engines.DataPool object can be used to apply log in/out information among multiple Klips can be found at http://developer.klipfolio.com/api/6/Engines.DataPool.html.