AppMachine Help Center

How can we help you?

Follow

Using published JavaScript Variables

The JavaScript block provides a feature called "Published JavaScript Variables" the variables can be specified in the AppMachine CMS and you can use them in your JavaScript code.

This might be very useful when you are creating your own building block using our JavaScript block. Because this allows you to expose a few settings - that you will be using in your JavaScript - to the users of your block.

How to specify JavaScript Variables?

Every JavaScript block has a section called "Published JavaScript variables" that allows you to create the variables you need.

  1. Go to https://design.appmachine.com and open the app containing your JavaScript block, or add a new JavaScript block to your app.
  2. The only thing you need to do is specify a name for your variable:

  3. Next you can specify the data type for this variable:
  4. And optionally you can specify a default value for your variable:

How to use JavaScript Variables?

After you have specified the variables you need, they will automatically be added to the core.js module and you will be able to use them.

function onLoad(){
	//We provide some properties like id and caption
	document.title = App.Properties.__caption;

	//Display the value of the myTextVariable
	alert('Value for myTextVariable:' + App.Properties.myTextVariable);
}

If you are working on your local machine and you might need to synchronize your core.js file so new published variables will be added.

To do so run the command: grunt get

Was this article helpful?
2 out of 2 found this helpful
Have more questions? Submit a request

Comments