Accessing Component Style using sightly

Avatar

Avatar
Shape 1
Level 2
toimrank
Level 2

Likes

9 likes

Total Posts

22 posts

Correct reply

1 solution
Top badges earned
Shape 1
Validate 1
Give Back
Boost 5
Boost 3
View profile

Avatar
Shape 1
Level 2
toimrank
Level 2

Likes

9 likes

Total Posts

22 posts

Correct reply

1 solution
Top badges earned
Shape 1
Validate 1
Give Back
Boost 5
Boost 3
View profile
toimrank
Level 2

21-05-2020

Hi All,

 

I have a business use case where I want to access component style system authored in editable template policy. I looked for an API and nothing similar available.

 

There is a property same in my content component node with cq:styleId. usiing this style id I want to access my style name authored in component style system as template policy.

 

Thanks in Advance.

Accepted Solutions (1)

Accepted Solutions (1)

Avatar

Avatar
Boost 500
MVP
Vijayalakshmi_S
MVP

Likes

586 likes

Total Posts

734 posts

Correct reply

246 solutions
Top badges earned
Boost 500
Give Back 50
Give Back 5
Ignite 10
Ignite 5
View profile

Avatar
Boost 500
MVP
Vijayalakshmi_S
MVP

Likes

586 likes

Total Posts

734 posts

Correct reply

246 solutions
Top badges earned
Boost 500
Give Back 50
Give Back 5
Ignite 10
Ignite 5
View profile
Vijayalakshmi_S
MVP

21-05-2020

Hi @toimrank,

We can write a query to get the style node (configured as policy) with the Id from the component node available under respective page content. 
(Style node in policy will have details of style label, style class and style id - Sample screenshot for reference below)
Sample query:

path=/conf/yourproject/settings/wcm/policies
type=nt:unstructured
1_property=cq:styleId
1_property.1_value=1590089010715
1_property.2_value=1590089575644
p.limit=-1

Where

  • path can be refined to specific component policy under main"policies" path based on the need
  • property.value predicate to be framed dynamically from the component node available under the desired content path(cq:styleIds - String[])
    For how many ever style Ids you have, frame property.value predicates accordingly.
  • Returned query result set will be the highlighted node and hence access to style label and class.

To be implemented in Sling Models or WCMUsePojo and expose the style class via getters for access in sightly.

Screenshot for reference:

stylepolicy.png

Answers (1)

Answers (1)

Avatar

Avatar
Boost 1
Level 1
divanshug96
Level 1

Likes

2 likes

Total Posts

1 post

Correct reply

0 solutions
Top badges earned
Boost 1
View profile

Avatar
Boost 1
Level 1
divanshug96
Level 1

Likes

2 likes

Total Posts

1 post

Correct reply

0 solutions
Top badges earned
Boost 1
View profile
divanshug96
Level 1

21-05-2020

Hi toimrank 

 

Please use the following to retrieve policy manager

ContentPolicyManager policyManager = resourceResolver.adaptTo(ContentPolicyManager.class);

ValueMap policyProperties = contentPolicy.getProperties();