Expand my Community achievements bar.

SOLVED

Conditionally adding selectors

Avatar

Level 5

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
Level 7

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

Avatar

Correct answer by
Level 7

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

Level 8

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>
page footer