내 커뮤니티 업적 표시줄을 확대합니다.

Submissions are now open for the 2026 Adobe Experience Maker Awards.

Mark Solution

활동이 없어 이 대화는 잠겼습니다. 새 게시물을 작성해 주세요.

해결됨

How to Use filter to parse and modify html to replace strings

Avatar

Level 2

Hi,

 

I am new to filters and would like to know how to modify the html on a page using them. My use case is such that I'm trying to dynamically look for certain strings in the html when rendering a page and replace them with another string (this is a very simplified version of what I'm trying to achieve but is a good summary).

 

I think filters would be a good candidate to achieve this however it is difficult to find resources on this. Any help is appreciated and I'd be happy to provide more details if necessary!

1 채택된 해결책 개

Avatar

정확한 답변 작성자:
Community Advisor

Sling filter

Sling supports filtering the request processing by applying filter chains to the requests before actually dispatching to the servlet or script for processing. Filters to be used in such filter processing are plain OSGi services of type javax.servlet.Filter which of course means that the services implement this interface.

So ib this case, if you want to intercept the request you can use filter but for your use case it is not the best option

 

Sling Rewrite/Transformer

The Apache Sling Rewriter is a module for rewriting the output generated by a usual Sling rendering process. Some possible use cases include rewriting or checking all links in an HTML page, manipulating the HTML page, or using the generated output as the base for further transformation. An example of further transformation is to use XSLT to transform rendered XML to some output format like HTML or XSL:FO for generating PDF.

https://sling.apache.org/documentation/bundles/output-rewriting-pipelines-org-apache-sling-rewriter....

 

 

 

HTML Parser can be used with either above of services.

 

Arun Patidar

AEM LinksLinkedIn

원본 게시물의 솔루션 보기

6 답변 개

Avatar

Community Advisor

Hi,

 

With your use case, I think you can achieve with html parser instead of filter

 

Check the below link

https://aem4beginner.blogspot.com/creating-html-parser-service-for-adobe

Avatar

Level 2

This link is giving 404 not found. Do you have an alternate resource?

Avatar

Level 2

Nevermind, it redirects!

Avatar

Community Advisor

In this case, you can do it using sling rewriter e.g.

https://wcm.io/handler/url/rewriter.html

 

Arun Patidar

AEM LinksLinkedIn

Avatar

Level 2

@arunpatidar @Ravi_Pampana what would you say the difference would be between using a Filter vs HTML Parser vs Service vs Rewriter vs Transformer? It's pretty confusing the difference and I would like to understand the difference before making a decision!

Avatar

정확한 답변 작성자:
Community Advisor

Sling filter

Sling supports filtering the request processing by applying filter chains to the requests before actually dispatching to the servlet or script for processing. Filters to be used in such filter processing are plain OSGi services of type javax.servlet.Filter which of course means that the services implement this interface.

So ib this case, if you want to intercept the request you can use filter but for your use case it is not the best option

 

Sling Rewrite/Transformer

The Apache Sling Rewriter is a module for rewriting the output generated by a usual Sling rendering process. Some possible use cases include rewriting or checking all links in an HTML page, manipulating the HTML page, or using the generated output as the base for further transformation. An example of further transformation is to use XSLT to transform rendered XML to some output format like HTML or XSL:FO for generating PDF.

https://sling.apache.org/documentation/bundles/output-rewriting-pipelines-org-apache-sling-rewriter....

 

 

 

HTML Parser can be used with either above of services.

 

Arun Patidar

AEM LinksLinkedIn