Checking an url if it contains specific text

Avatar

Avatar

sai_santhosht50

Avatar

sai_santhosht50

sai_santhosht50

24-09-2020

There is a requirement in our project where i have to check if the current page path contains a specific text or not. How to write sightly code for this.

 

for ex:- <sly data-sly-test.pagepath=${currentPage.path}/> 

this will returns path as "/content/project/ab/cd/home/" now i want to check if it has " /cd/ " text in it.
Thanks in advance.

Package Manager sightly
View Entire Topic

Avatar

Avatar

raj_mandalapu

Avatar

raj_mandalapu

raj_mandalapu

24-09-2020

The sightly does not support this, you need to write java code, refer below link for writing the sling model

http://www.aemcq5tutorials.com/tutorials/adobe-aem-cq5-tutorials/sling-model-sightly-aem/

1. your class adaptable from SlingHttpServletRequest

2 add the following inject 

@inject

private Page currentPage;

3: check path contains /cd/

 

 

currentPage.path.contains("/cd/")