Leiste mit Community-Erfolgen erweitern.

Submissions are now open for the 2026 Adobe Experience Maker Awards.

Mark Solution

Diese Konversation wurde aufgrund von Inaktivität geschlossen. Bitte erstellen Sie einen neuen Post.

GELÖST

Get selector value from sightly html page [Bit Urgent : Any thoughts on this will be helpful]

Avatar

Level 9

Hi All,

Via Java code, we are able to get the selectors by "request.getRequestPathInfo().getSelectors()" . On a component html[making use of sightly code], how do I retrieve the selector value on that page.

Any thoughts on this will be really helpful.

1 Akzeptierte Lösung

Avatar

Korrekte Antwort von
Level 10

Or you can just use Sling Model instead of Sightly Model

 

@Model(adaptables = SlingHttpServletRequest.class) public class SelectorCheck{ @Inject SlingHttpServletRequest request; private boolean enabled = false; @PostConstruct public void postConstruct() { if (request != null) { List<String> selectors = Arrays.asList(request.getRequestPathInfo().getSelectors()); enabled = selectors.contains("abc"); } } public boolean isEnabled() { return enabled; } }

Lösung in ursprünglichem Beitrag anzeigen

7 Antworten

Avatar

Level 10

For this use case, make use of a java bean. 

Avatar

Level 8
${request.requestPathInfo.selectors[0]}

Avatar

Level 2

use a request scoped sling model and use that to get the selector and then use that on your sightly script.

Avatar

Level 10

Hi, 

Find the example below 

 

Sightly HTML

<div data-sly-use.selectorCheck="com.foo.SelectorCheck"> <div data-sly-test="!selectorCheck.enabled" >Selector Content</div> </div>

Sightly Model

public class SelectorCheck extends WCMUse { @Inject SlingHttpServletRequest request; private boolean enabled = false; @Override public void activate() throws Exception { if (request != null) { List<String> selectors = Arrays.asList(request.getRequestPathInfo().getSelectors()); enabled = selectors.contains("abc"); } } public boolean isEnabled() { return enabled; } }

Avatar

Korrekte Antwort von
Level 10

Or you can just use Sling Model instead of Sightly Model

 

@Model(adaptables = SlingHttpServletRequest.class) public class SelectorCheck{ @Inject SlingHttpServletRequest request; private boolean enabled = false; @PostConstruct public void postConstruct() { if (request != null) { List<String> selectors = Arrays.asList(request.getRequestPathInfo().getSelectors()); enabled = selectors.contains("abc"); } } public boolean isEnabled() { return enabled; } }

Avatar

Level 9

Hi All,

Thank you for your replies. Trying on it.

Avatar

Level 9

Hi All,

Apologies for the delay in responding back.

Using Sling model helped. But somehow, I do not get an option to mark the answer as resolved.