Expand my Community achievements bar.

Dive into Adobe Summit 2024! Explore curated list of AEM sessions & labs, register, connect with experts, ask questions, engage, and share insights. Don't miss the excitement.
SOLVED

Append a value inside a resource called by data-sly-resource via htl.

Avatar

Level 3

I have a button component with property "link" and called by parent component via "data-sly-resource".
Is there a way to append a string (or a query parameters) to the link inside of button component via HTL? (or is there a recommended solution for that without JS?)
Thanks!

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

Hi @LyonMartin 

Yes, You can pass it via selectors while including the resource  as shown below in your parent component:

<div class="heading"
data-sly-resource="${ './headingItem' @ resourceType='weretail/components/heading-item', selectors=['underline','style_h1'] }"></div>

 and in your heading-item component either Use JS or sling model, you can retrieve the selectors using below and write your business logic

request.getRequestPathInfo().getSelectors())

 

View solution in original post

3 Replies

Avatar

Community Advisor

@LyonMartin For passing the parameter from sightly to the sling model

<a class="title-text" data-sly-use.linkResolve="${'com.sourcedcode.core.utils.use.LinkResolve' @ href='/content/sourcedcode/home'}" href="${linkResolve.href}" target="${linkResolve.target}" rel="noopener">
    ${linkResolve.href}
</a>

And in the Sling model

@Model(adaptables = SlingHttpServletRequest.class)
public class LinkResolve {

    @RequestAttribute
    private String href;

 public String getHref() {
        return href;
    }

 @PostConstruct
    public void init() {
}

}

 

Avatar

Correct answer by
Community Advisor

Hi @LyonMartin 

Yes, You can pass it via selectors while including the resource  as shown below in your parent component:

<div class="heading"
data-sly-resource="${ './headingItem' @ resourceType='weretail/components/heading-item', selectors=['underline','style_h1'] }"></div>

 and in your heading-item component either Use JS or sling model, you can retrieve the selectors using below and write your business logic

request.getRequestPathInfo().getSelectors())