How to show multi field images in java model | Community
Skip to main content
New Participant
December 5, 2023
Solved

How to show multi field images in java model

  • December 5, 2023
  • 2 replies
  • 877 views

I have a requirement to build a website where i can add more and more images using multifield. How will the java model of this feature look like?

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 BrianKasingli

If you're looking to create a website where you can add a bunch of images using a multifield, you're on the right track! In the Java model (Sling Model) part, we use the @ChildResource annotation to map a child node named "links" to a List of Resource objects. This sets the stage for creating a multifield.

 

Now, in the Sightly template, we're using the data-sly-list directive to loop through each item in the "links" List. Inside the loop, we access the properties of each link Resource to display things like the link path, target, and label. It's a neat way to handle multifields and makes it super easy for authors to add and manage multiple link items.

Feel free to give it a try, and if you have more questions or need clarification, just let me know!

I created a blog where you can use a simple Sling Model and sightly to iterate each item to build your frontend experience as you wish, check it out here. https://sourcedcode.com/blog/aem/granite-ui-multifield-sightly-traverse-iterate-simple-example

2 replies

BrianKasingli
BrianKasingliAccepted solution
New Participant
December 6, 2023

If you're looking to create a website where you can add a bunch of images using a multifield, you're on the right track! In the Java model (Sling Model) part, we use the @ChildResource annotation to map a child node named "links" to a List of Resource objects. This sets the stage for creating a multifield.

 

Now, in the Sightly template, we're using the data-sly-list directive to loop through each item in the "links" List. Inside the loop, we access the properties of each link Resource to display things like the link path, target, and label. It's a neat way to handle multifields and makes it super easy for authors to add and manage multiple link items.

Feel free to give it a try, and if you have more questions or need clarification, just let me know!

I created a blog where you can use a simple Sling Model and sightly to iterate each item to build your frontend experience as you wish, check it out here. https://sourcedcode.com/blog/aem/granite-ui-multifield-sightly-traverse-iterate-simple-example

aanchal-sikka
New Participant
December 5, 2023