Passing data to an embedded component via data-sly-resource | Community
Skip to main content
darren_hoffman
Level 2
March 18, 2016

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

  • March 18, 2016
  • 1 reply
  • 11257 views

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?

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.

1 reply

Kunal_Gaba_
March 18, 2016

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-manager.topic.html/forum__vfy1-i_am_tryingtoimple.html

darren_hoffman
Level 2
March 18, 2016

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?

smacdonald2008
Level 10
March 18, 2016

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