Diese Konversation wurde aufgrund von Inaktivität geschlossen. Bitte erstellen Sie einen neuen Post.
Level 1
Level 2
Melden Sie sich an, um alle Badges zu sehen
Diese Konversation wurde aufgrund von Inaktivität geschlossen. Bitte erstellen Sie einen neuen Post.
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.
Gelöst! Gehe zu Lösung.
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; } }
Zugriffe
Antworten
Likes gesamt
For this use case, make use of a java bean.
Zugriffe
Antworten
Likes gesamt
${request.requestPathInfo.selectors[0]}
use a request scoped sling model and use that to get the selector and then use that on your sightly script.
Zugriffe
Antworten
Likes gesamt
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; } }
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; } }
Zugriffe
Antworten
Likes gesamt
Hi All,
Thank you for your replies. Trying on it.
Zugriffe
Antworten
Likes gesamt
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.
Zugriffe
Antworten
Likes gesamt
Zugriffe
Likes
Antworten
Zugriffe
Likes
Antworten
Zugriffe
Likes
Antworten