check if the page url contain specific text | Community
Skip to main content
ebin_Aby
Level 2
August 7, 2019
Solved

check if the page url contain specific text

  • August 7, 2019
  • 2 replies
  • 4081 views

In htl how can we check if the page URL contains specific text ?  ( intend to do it on the page rather than by Java )

${'a' in 'abc'} <!--/* returns true */-->  does not work  
This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by arunpatidar

Hi,

It may not be working because of old HTL version (Shipped with AEM)

please check specifications at htl-spec/CHANGELOG.md at master · adobe/htl-spec · GitHub

I tried in AEM 6.5, it works.

2 replies

arunpatidar
Community Advisor
arunpatidarCommunity AdvisorAccepted solution
Community Advisor
August 8, 2019

Hi,

It may not be working because of old HTL version (Shipped with AEM)

please check specifications at htl-spec/CHANGELOG.md at master · adobe/htl-spec · GitHub

I tried in AEM 6.5, it works.

Arun Patidar
rampai
Community Advisor
Community Advisor
August 8, 2019

Does not work in AEM 6.4 GA.

You can try using a small use js file and pass it the test string value as shown below:

Or go for Java.

filepath.js:

use(function () {

    var testStr= this.value;

    var retValue = currentPage.path.toLowerCase().contains(testStr.toLowerCase());

    return {

        hasString: retValue

    };

});

HTL Code:

<div data-sly-use.path="${'filepath.js' @ value='demo-page'}">

    ${path.hasString}

</div>

I have converted both strings to lower case for case insensitive check.