Expand my Community achievements bar.

Passing data to an embedded component via data-sly-resource

Avatar

Level 2

I am following the documentation and other posts (stackoverflow, etc.) to find a way to pass parameters to an embeded component. My goal is to create the embedded component that can receive and make use of this data; I also have control over the wrapper component.

In the wrapper component I am embedding using this syntax:

<sly data-sly-resource="${'embeddedComponent' @ resourceType='my/components/embeddedComponent', myParam='myValue'}"></sly>

On the server, I have a Java Use class:

public class MyHelper extends WCMUse {private String myParam = "myDefaultValue";@Override    public void activate() throws Exception {this.myParam = get("myParam", String.class); }public String getMyParam() {return myParam; } }

And in my embedded Sightly template, I get the parameter like this:

<sly data-sly-use.helper="com.my.project.helper.MyHelper"><input type="hidden" value="${helper.myParam}" /></sly>

I have done some debugging and discovered that myParam is not in the set of Bindings[] sent to the MyHelper class, and for this reason is not available to the embedded template.

Can anyone help by enlightening me about the correct way to pass information to the embedded component's Sightly template?

5 Replies

Avatar

Employee Advisor

I think you can not pass custom params via data-sly-resource. However, you can use selectors instead of custom params. Take a look at the following thread - http://help-forums.adobe.com/content/adobeforums/en/experience-manager-forum/adobe-experience-manage...

Avatar

Level 2

I don't know exactly how the selectors implementation can be leveraged, but my first understanding will not meet my needs. "Selectors" implies a set of parameters that Sling can use in the selection of resources from the JCR. What I need is to use this value client-side in the javascript backing the page.

Can selectors be used that way?

Avatar

Level 10

Using dialog values is the way values are typically passed to a Sightly component. 

Avatar

Level 2

I'm sorry, I don't see anything relevant to my situation. I see that you're using the :data-sly-resource" directive, and that it includes a "path" variable, but I'm pretty sure that doesn't fit my use case.

I'm sure I don't fully understand the "path" parameter here, but I infer that you're directing the embedded parsys to find its parameters in the "tab-1" and "tab-2" tabs in the relative path of this component. This means that the author can configure the "tab-component" and that embedded components can pick up those configuration parameters, but I want the developer to configure the embedded parameter without having to visit the Author interface.