Expand my Community achievements bar.

How to use Sling model for CQ Page ?

Avatar

Level 4

Hi,

I am looking for some solutions on how to use the Sling models for CQ Pages.

For example, how the Sling model would look like, if I want to adapt the following page:

/content/geometrixx-media/en/entertainment/summer-blockbuster-hits-and-misses 

4 Replies

Avatar

Level 4

Thanks Kishore.

The questions is specifically when the resource = cq:Page.

How will the Sling model look like ?    

Avatar

Level 10

We talked about this in that thread. 

http://help-forums.adobe.com/content/adobeforums/en/experience-manager-forum/adobe-experience-manage...

You would not do sling  model on a cq:page node  - ie:

/content/geometrixx-outdoors

A cq:page does not have props to let you model it.

You would use sling model on a cq:PageContent - ie: 

/content/geometrixx-outdoors/jcr:content

Avatar

Level 10

FRom the SLing Model Docs: https://sling.apache.org/documentation/bundles/models.html

Basic Usage

In the simplest case, the class is annotated with @Model and the adaptable class. Fields which need to be injected are annotated with@Inject:

@Model(adaptables=Resource.class)public class MyModel {@Injectprivate String propertyName;}

In this case, a property named "propertyName" will be looked up from the Resource (after first adapting it to a ValueMap) and it is injected.

A cq:page does not have props like jcr:title or jcr:description.