Skip to Content
0

Can you pass values from component.js to contribution.ztl?

Jan 25, 2017 at 03:52 PM

96

avatar image

Can I set the values of parameters in my component.js file (using the getter/setter functions) and then access values in the code of the contribution.ztl file?

Example:

contribution.xml (no defaultValue is set)

<property 
id="selectedElement" 
title="Selected Element" 
type="int" visible="false"/>

component.js

var that = this;

that._selectedElement = 0;

that.selectedElement = function(val) {
	if (val === undefined) {
		return that._selectedElement;
	} else {
		that._selectedElement = val;
		return this;
	}
};

// var x is assigned int value

that.selectedElement(x);

contribution.ztl

/* Returns the index of the selected item */
int getSelectedMember(){*
	return this.selectedElement;
*}

Now when I use .getSelectedMember() in my script, I expect it to return the values I set in my component.js (var x). Instead, it always returns 0.

Is it possible to access parameter values set by component.js in the contribution.ztl code?

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

1 Answer

Best Answer
Mustafa Bensan Jan 25, 2017 at 04:18 PM
1

Hi Nikolaus,

This should be possible. However, remember that the contribution.ztl runs on the server and the component.js runs on the client. You might have to execute a firePropertiesChanged() call to send the property value to the server.

Regards,

Mustafa.

Share
10 |10000 characters needed characters left characters exceeded