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.
Solved! Go to Solution.
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; } }
Views
Replies
Total Likes
For this use case, make use of a java bean.
Views
Replies
Total Likes
${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.
Views
Replies
Total Likes
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; } }
Views
Replies
Total Likes
Hi All,
Thank you for your replies. Trying on it.
Views
Replies
Total Likes
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.
Views
Replies
Total Likes
Views
Likes
Replies
Views
Likes
Replies