This article explains how to set and subscribe to Blocks properties from Google Web Designer using a custom component available for download on this page. It is assumed that the reader is familiar with Google Web Designer.
To install the PIXILAB Blocks Property custom component, download this ZIP file and install it according to the official installation instructions.
When placed in a Google Web Designer document, the PIXILAB Blocks Property component provides a set of events and actions for getting and setting the value of a specific Blocks property. The "Property changes", "Property becomes true" and "Property becomes false" events can be used to react to property changes, and the "Set property value" action can be used to set the value of the property. PIXILAB Blocks Property components are visible in the Google Web Designer editor, but will not be visible in the final result.
A PIXILAB Blocks Property component must be configured before it can be used: Select the component, open the Properties tab and scroll down to the "PIXILAB Blocks Property" section. Set the property path and choose whether to subscribe to property changes or not.
Tips: To easily determine the path of a Blocks property, you can create a "dummy" Task (on the Tasks page in the Blocks editor), set the trigger to "Property change" and select the property using the dropdown menus. When you have selected the property, you can click the pen icon to bring up the property path, which can be copied.
When using the "Preview" functionality in Google Web Designer, or if the final result is not going to be served by the Blocks server, the WebSocket URL to the Blocks server must be specified. Open the "Code view" and add the following lines at the top of the main HTML file, under the "<head>" tag:
<script type="text/javascript"> var BLOCKS_WEBSOCKET_URL = "ws://<nameOrIp><:nonStandardPort>/rpc/pub-sub"; </script>
Replace <nameOrIp> with the IP number or resolvable name to your Blocks server. If you're using HTTPS to access your Blocks server, specify "wss:" as the protocol instead of "ws:". If you're running on a non-standard port, append the port number separated by a colon.
Launch the Preview and click the button. Go to the Task page in Blocks. The log statement shows that the "test" Task was executed:
document.getElementById("test").textContent = event.detail.value;
Launch the Preview. The text now shows the value of the "test" Realm variable. If the "test" Realm variable changes, a "Property changes" event will be fired, and the custom action will update the text.