Expand my Community achievements bar.

Learn about Edge Delivery Services in upcoming GEM session
SOLVED

Conditionally adding selectors

Avatar

Level 6

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

 

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

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

View solution in original post

2 Replies

Avatar

Correct answer by
Community Advisor

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

Avatar

Community Advisor

Hello @kevingtan,
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>