Expand my Community achievements bar.

Guidelines for the Responsible Use of Generative AI in the Experience Cloud Community.
SOLVED

How to transform a link in a content fragment field

Avatar

Level 5

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?

1 Accepted Solution

Avatar

Correct answer by
Employee Advisor

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.

View solution in original post

8 Replies

Avatar

Employee Advisor

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.

Avatar

Level 5

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

Avatar

Correct answer by
Employee Advisor

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.

Avatar

Level 5

Yes, the links are appearing on the site's page but they are not transformed. Whereas the link transformer is working fine for other components.

Avatar

Employee Advisor

Can you share the snippet from you page source, how it is rendering on the page.

Avatar

Level 3

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