adaptTo() in sightly | Community
Skip to main content
Level 4
August 28, 2017
Solved

adaptTo() in sightly

  • August 28, 2017
  • 7 replies
  • 4324 views

Hi All,

is there a way to adapt a resource to custom model class in sightly?

I have a custom model and i want to adapt a resource to it in sightly html code not in java.

Thanks,

Khalid

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 Feike_Visser1

Sure this is possible. By default classes used in data-sly-use will be adapted from request or resource.

7 replies

Feike_Visser1
Adobe Employee
Feike_Visser1Adobe EmployeeAccepted solution
Adobe Employee
August 28, 2017

Sure this is possible. By default classes used in data-sly-use will be adapted from request or resource.

Level 4
August 28, 2017

Thanks Feike,

Any code snippet or sample?

Feike_Visser1
Adobe Employee
Adobe Employee
August 28, 2017

<div data-sly-use.x="a.b.c">

${x.yourProperty}

</div>

Level 4
August 28, 2017

A function is returning me an object which is of type "Resource", i want to cast it to my model class.

like we do in java : Model model=resource.adaptTo(Model.class);

Something similar to this.

Feike_Visser1
Adobe Employee
Adobe Employee
August 28, 2017

Note that currently the page-resource is used for adapting.

I raised this improvement [SLING-6504] Use-api to support more flexible way to adapt from different objects - ASF JIRA

Level 4
August 28, 2017

Hi Feike,

I am a bit confused with this.

Can you provide me a snippet only instead of JIRA issue?

Feike_Visser1
Adobe Employee
Adobe Employee
August 28, 2017

I gave you the snippet already, right?

The JIRA is not yet released.