Conditionally adding selectors | Community
Skip to main content
Level 5
April 5, 2023
Solved

Conditionally adding selectors

  • April 5, 2023
  • 2 replies
  • 614 views

Hi All,

 

Suppose I have a default component /path/to/menu, and I like to add a selector to it if it meets a condition, can I do this?

 

// - page is a sling model defined above

<sly data-sly-resource="${@ resourceType='/path/to/menu', data-sly-test=page.collapsedMenu? selectors='collapsed':selectors=''}"></sly>

 

If not, what would be a possible way doing this within HTL?

 

Thanks!

 

-kt

 

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 DPrakashRaj

I believe to call a component or service based on selector the selector should be part of request url and not with htl. If your component has selector.htl it will automatically get called but in this case you need to call the component selector via page jcr:content component path

2 replies

DPrakashRaj
Community Advisor
DPrakashRajCommunity AdvisorAccepted solution
Community Advisor
April 6, 2023

I believe to call a component or service based on selector the selector should be part of request url and not with htl. If your component has selector.htl it will automatically get called but in this case you need to call the component selector via page jcr:content component path

Sady_Rifat
Community Advisor
Community Advisor
April 6, 2023

Hello @kevin_gta,
Yes, this is possible. You can call the conditional selectors this way ->

<sly data-sly-resource="${@ resourceType='/path/to/menu', selectors=page.collapsedMenu ? 'collapsed' : '' }"></sly>