Expand my Community achievements bar.

SOLVED

Inject Child Pages using Sling Models

Avatar

Level 6

Hi,

Is it possible to inject the Child Pages using Sling models?

Thanks

1 Accepted Solution

Avatar

Correct answer by
Employee

What is your usecase. Injecting child resource is possible. Please refer to https://sling.apache.org/documentation/bundles/models.html

List injection for child resources works by injecting grand child resources (since Sling Models Impl 1.0.6). For example, the class

@Model(adaptables=Resource.class)public class MyModel {@Injectprivate List<Resource> addresses;}

Is suitable for a resource structure such as:

+- resource (being adapted)|+- addresses|+- address1|+- address2

In this case, the addresses List will contain address1 and address2.

View solution in original post

3 Replies

Avatar

Level 10

For Sling Models - see these Apache docs:

https://sling.apache.org/documentation/bundles/models.html#custom-injectors 

I have not seen too many examples of using Sling Models in AEM. I will determine if we have examples internally. 

Avatar

Correct answer by
Employee

What is your usecase. Injecting child resource is possible. Please refer to https://sling.apache.org/documentation/bundles/models.html

List injection for child resources works by injecting grand child resources (since Sling Models Impl 1.0.6). For example, the class

@Model(adaptables=Resource.class)public class MyModel {@Injectprivate List<Resource> addresses;}

Is suitable for a resource structure such as:

+- resource (being adapted)|+- addresses|+- address1|+- address2

In this case, the addresses List will contain address1 and address2.

Avatar

Level 6

Hi @kalyanar,

I would like to have a class that I would adapt from Page, and wanted that its children were already injected, to not need to call listChildren.

Thanks