adaptTo() in sightly | Community
Skip to main content
Level 4
Aug 28, 2017 7:11 AM UTC
Solved

adaptTo() in sightly

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.
Feike_Visser1
Feike_Visser1Accepted solution
Employee
Aug 28, 2017 7:46 AM UTC

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

7 replies

Feike_Visser1
Employee
Aug 28, 2017 10:50 AM UTC

I gave you the snippet already, right?

The JIRA is not yet released.

Translate
Level 4
Aug 28, 2017 10:42 AM UTC

Hi Feike,

I am a bit confused with this.

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

Translate
Feike_Visser1
Employee
Aug 28, 2017 9:29 AM UTC

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

Translate
Level 4
Aug 28, 2017 9:21 AM UTC

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.

Translate
Feike_Visser1
Employee
Aug 28, 2017 9:18 AM UTC

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

${x.yourProperty}

</div>

Translate
Level 4
Aug 28, 2017 9:11 AM UTC

Thanks Feike,

Any code snippet or sample?

Translate
Feike_Visser1
Feike_Visser1Accepted solution
Employee
Aug 28, 2017 7:46 AM UTC

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

Translate