Append a value inside a resource called by data-sly-resource via htl. | Community
Skip to main content
Level 3
June 27, 2022
Solved

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

  • June 27, 2022
  • 3 replies
  • 1559 views

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!

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 ArpitVarshney

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())

 

3 replies

ShaileshBassi
Community Advisor
Community Advisor
June 27, 2022

@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() {
}

}

 

ArpitVarshney
Community Advisor
ArpitVarshneyCommunity AdvisorAccepted solution
Community Advisor
June 27, 2022

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())

 

arunpatidar
Community Advisor
Community Advisor
June 27, 2022