Expand my Community achievements bar.

Don’t miss the AEM Skill Exchange in SF on Nov 14—hear from industry leaders, learn best practices, and enhance your AEM strategy with practical tips.
SOLVED

Mapping Image URLs in Sightly Templates (AEM 6.1)

Avatar

Level 3

Hi Everyone,

I'm using /etc/map rules to remove /content/appname from requests. This works properly for incoming HTTP requests.

However, image tags rendered in Sightly templates are not rewritten. For example, if I have an image component at /content/app1/en/news/image, the src attributes in the image tag is not rewritten. It's still something like

<img src="/content/app1/en/news/image.img.jpg/123456789.jpg">

I would like it to be

<img src="/en/news/image.img.jpg/123456789.jpg">

I tried adding "img:src" to the set of mappings in Link Checker Transformer but this has no effect.

I assume I can create a custom rewriter/transformer to resolve this issue but it seems like this is something that should work automatically.

Any suggestions?

Thanks in advance,

David Frenkiel

1 Accepted Solution

Avatar

Correct answer by
Level 3

Thanks for all the comments, everyone. I believe this is the solution:

I need to configure the Sling Rewriter as described here:

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

It's a special configuration that goes under /apps/{appName}/config/rewriter/{configName}.

The important part looks like this:

<generator-htmlparser jcr:primaryType="nt:unstructured" includeTags="[A,/A,IMG,AREA,FORM,BASE,LINK,SCRIPT,BODY,/BODY,META,SOURCE]"/>

Also note that that the {appName} part of the configuration path MUST be a single node.

You can't have something like /apps/company/app1/config/... Sling will ignore it.

 

View solution in original post

5 Replies

Avatar

Level 3

Hi Jitendra,

Thanks for the suggestion.

I tried adding a few different mappings for /content/dam but it doesn't seem to make a difference.

For now I'm mapping /content/dam to itself so that it's effectively excluded from the mapping. So direct requests to images under /content/dam work correctly.

However, regardless of how I map /content/dam, image components continue to render with /content/app1 in the path.

Thanks,

David

Avatar

Level 9

@davidf46996755,

Before developing custom re-writer to solve this problem, I would suggest, you raise a day care ticket and ask why is it not working?.  Creating custom solution isn't the right move for every problem.

--

Jitendra

Avatar

Correct answer by
Level 3

Thanks for all the comments, everyone. I believe this is the solution:

I need to configure the Sling Rewriter as described here:

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

It's a special configuration that goes under /apps/{appName}/config/rewriter/{configName}.

The important part looks like this:

<generator-htmlparser jcr:primaryType="nt:unstructured" includeTags="[A,/A,IMG,AREA,FORM,BASE,LINK,SCRIPT,BODY,/BODY,META,SOURCE]"/>

Also note that that the {appName} part of the configuration path MUST be a single node.

You can't have something like /apps/company/app1/config/... Sling will ignore it.

 

Avatar

Level 3

Hmmmm...

Maybe I'm mistaken. This doesn't seem to work without a custom transformer.