Passing paramater to the resource from HTL/Sightly template | Community
Skip to main content
New Participant
November 18, 2022
Solved

Passing paramater to the resource from HTL/Sightly template

  • November 18, 2022
  • 1 reply
  • 2541 views

I have a component that uses two different resources in its HTL/Sightly template.

Is there a way to pass a parameter, to the say in my example the eventResource template, so that I can depending on this passed paramter change a css class on it?

<ul data-sly-list.teasers="${model.resourceList}" class="teaser-list-alternating c-list--reset">
<sly data-sly-test="${teasers.eventTeaser}"
data-sly-resource="${teasers.resource @ resourceType='xxx/components/content/eventTeaser'}"></sly>
<li data-sly-test="${teasers.contentTeaser}" class="l-stack l-stack--horse"
data-component-hook-content-hub="teaser"
data-sly-resource="${teasers.resource @ resourceType='xxx/components/content/contentHubTeaser'}"></li>
</ul>

I tried using `data-sly-resource="${teasers.resource @ resourceType='xxx/components/content/eventTeaser', requestAttributes=model.config, selectors='blabla'}` to no availability.

@RequestAttribute(name = "contentHub")
private String contentHub;

The requestAttribute `contentHub` in the eventTeaser model is alway null and I am not sure how to get the selectors value in the eventTeaser template.

I can do it using TypeScript on the front end part but it is not very clean.

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 arunpatidar

Hi, 

Please check HTL specification https://github.com/adobe/htl-spec/blob/master/SPECIFICATION.md#229-resource

You can't pass parameters but you can add selectors.

1 reply

arunpatidar
arunpatidarAccepted solution
New Participant
November 18, 2022

Hi, 

Please check HTL specification https://github.com/adobe/htl-spec/blob/master/SPECIFICATION.md#229-resource

You can't pass parameters but you can add selectors.

Arun Patidar
anasusticAuthor
New Participant
November 18, 2022

Hi 

Thanks for your answer. I read the specifications several times but I am not sure how can I use the selectors in the other component.

 

Say I use the selectors like this. 

<sly data-sly-test="${teasers.eventTeaser}"
data-sly-resource="${teasers.resource @ resourceType='xxx/components/content/eventTeaser', selectors='selector1.selector2'}"></sly

 I am sorry but I am not clear how to fetch the selectors in the eventTeaser Model or its respective HTL/Sightly template?

arunpatidar
New Participant
November 18, 2022