Fetching image component using a relative path
-- responsivegrid
----- responsivegrid_123421
Hi @melaniejo ,
Inside your Sling Model, you can iterate through all the children resources and then can make a list of those, the same you can iterate on HTL side, for example-
Sling Model-
@SlingObject
Resource resource;
List<ImageModel> images; //ImageModel can be simple Resource or if you want to add custom props
public List<ImageModel> getImages() {
if (images== null) {
try (Stream<Resource> stream = StreamSupport.stream(resource.getChildren().spliterator(), false)) {
images= stream.map(r -> r.adaptTo(ImageModel.class)).filter(Objects::nonNull)
.collect(Collectors.toList());
}
}
return images;
}
HTL code -
<sly data-sly-list.mediaModel="${model.images}">
<p>${mediaModel.resource.path}</p>
<sly
data-sly-resource="${@path= mediaModel.resource.path, resourceType=mediaModel.resource.resourceType, decorationTagName='div'}" />
</sly>
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.