How to transform a link in a content fragment field | Community
Skip to main content
Level 4
February 28, 2022
Solved

How to transform a link in a content fragment field

  • February 28, 2022
  • 2 replies
  • 3038 views

I have used Content Reference in a content fragment. Basically, my need is to redirect the content fragment to the link inserted in the content reference field whenever it is clicked. But the problem is the redirection is done to the exact link which I insert in the field. For eg: if I save link as, /conten/wknd/en/..., the redirection link will be same. But I want that when the redirection is done, the /content/wknd/en/ should be removed from the link. I did it with js and it's working fine. But I want to try any other method like using link transformer. Is there any other way to do this?

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 Anish-Sinha

Is your link appearing on a sites page (component is rendering the content on html page)? If so, the link transformer should modify the link if that is handled in the code. Transformer code should read the correct tag in order to modify the link. Also, if the links are on page, you can use sling mappings too.

2 replies

Anish-Sinha
Adobe Employee
Adobe Employee
February 28, 2022

Hi @nikita24tailor ,
There are two ways you do a URL shortening in AEM:

1. Sling Mappings - https://blog.3sharecorp.com/shortening-urls-in-aem

2. Using Sling Transformers in AEM - https://wttech.blog/blog/2019/how-to-use-sling-transformers-in-aem/

Depending on your implementation, you can chose either of the two solutions. Sling Mapping is an OOTB implementation where you can transform your URL with some configuration. This is straight forward. If you use Sling Transformers, you have to write a class, and you can manipulate the URL in any tag. Please go through both the links I shared. Let me know if this satisfies your requirement.

Level 4
February 28, 2022

Link transformation is already done for the project but that is not working in this case of content fragment.

Anish-Sinha
Adobe Employee
Anish-SinhaAdobe EmployeeAccepted solution
Adobe Employee
February 28, 2022

Is your link appearing on a sites page (component is rendering the content on html page)? If so, the link transformer should modify the link if that is handled in the code. Transformer code should read the correct tag in order to modify the link. Also, if the links are on page, you can use sling mappings too.

Level 2
March 2, 2022

Hi @nikita24tailor - Is the content fragments parent path added to the paths[] property of the rewriter configuration? 

Level 4
March 3, 2022

Thanks, the problem has been solved.