Passing paramater to the resource from HTL/Sightly template | Community
Skip to main content
Level 6
Nov 18, 2022 8:08 AM UTC
Solved

Passing paramater to the resource from HTL/Sightly template

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.
arunpatidar
arunpatidarAccepted solution
New Participant
Nov 18, 2022 8:19 AM UTC

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

4 replies

arunpatidar
arunpatidarAccepted solution
New Participant
Nov 18, 2022 8:19 AM UTC

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.

Translate
Arun Patidar
anasusticAuthor
Level 6
Nov 18, 2022 9:50 AM UTC

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?

Translate
arunpatidar
New Participant
Nov 18, 2022 12:32 PM UTC
Arun Patidar