Expand my Community achievements bar.

Don’t miss the AEM Skill Exchange in SF on Nov 14—hear from industry leaders, learn best practices, and enhance your AEM strategy with practical tips.

How to pass parameters to components?

Avatar

Level 2

I'm rendering out a component via a data-sly-resource and I'd like to be able to pass parameters as part of this, for example something like <sly data-sly-resource="${'featuredPost' @ showComments=false}"></sly> or something. I'd rather keep it out of the dialog because it's not something authors need to worry about and I'd rather not create separate resource types to handle different rendering scenarios for the same content. Is there a way to do this?

6 Replies

Avatar

Level 10

This is discussed here: 

http://blogs.adobe.com/experiencedelivers/experience-management/sightly-intro-part-3-2/

 

Use-api

In my second article I explained that you can call methods from your custom-classes via the data-sly-use notation.
In this example I will show that you can also pass in parameters from your components.

However - values are passed from front end to the back end - which is Java. 

If you want to get values to the component itself (ie - a String value)- you need to use a dialog. 

Avatar

Level 2

smacdonald2008 wrote...

This is discussed here: 

http://blogs.adobe.com/experiencedelivers/experience-management/sightly-intro-part-3-2/

 

Use-api

In my second article I explained that you can call methods from your custom-classes via the data-sly-use notation.
In this example I will show that you can also pass in parameters from your components.

However - values are passed from front end to the back end - which is Java. 

If you want to get values to the component itself (ie - a String value)- you need to use a dialog. 

 

 

Looks like the method shown in that link would just pass parameters into the use file, which is called from within the component, and not into the component itself?

Avatar

Level 10

Correct - that blog talks about getting values to the Java part of the Sightly code. 

The way to  get values passed to the Sightly component is to use a dialog and code like: 

<div id="experiencetext">${properties.contactDescription}</div>

See this Sightly article for more details: 

https://helpx.adobe.com/experience-manager/using/movie.html

Avatar

Level 2

I'd rather not use a dialog because it is not an authorable property.

Avatar

Level 10

Another option to explore is using Java and then use OSGi config values: 

https://helpx.adobe.com/experience-manager/using/osgi_config.html

You can set values in the JCR which are picked up by Java logic.