Expand my Community achievements bar.

SOLVED

Does CQ provide a way to change or strip the suffix from the current URL but preserve the query params?

Avatar

Level 7

Hi,

I am looking for a way to transform the current request URL into one with a different suffix and preserve everything else.

Does CQ (or Sling) has an API for doing this? Or do I have to do it manually, maybe with some help from slingRequest.getRequestPathInfo()?

Thanks,
Behrang

1 Accepted Solution

Avatar

Correct answer by
Level 10

You can get the suffix, selectors from the URL (https://sling.apache.org/apidocs/sling5/org/apache/sling/api/request/RequestPathInfo.html) but there is nothing to replace it. Hope you are already doing the same !

View solution in original post

3 Replies

Avatar

Level 10

I am not aware of any such methods in APIs. you should handle it manually.

but can you explain a usecase here ?

Avatar

Level 7

We have a requirement to implement pagination and to use path variables rather than query parameters (e.g. /books/1, /books/2, etc. rather than /books?page=1, /books?page=2, etc.)

In this case, /1, /2, etc. are resolved as suffixes by CQ. So I need to extract the suffix and replace it. At the moment I am doing it manually, but it would be nice if there was a way to transform the current URL into another one with selector, suffix, etc. replaced with different values.

Avatar

Correct answer by
Level 10

You can get the suffix, selectors from the URL (https://sling.apache.org/apidocs/sling5/org/apache/sling/api/request/RequestPathInfo.html) but there is nothing to replace it. Hope you are already doing the same !