can anyone please help me with this sling model for multifield with sightly | Community
Skip to main content
Level 2
March 19, 2024
Question

can anyone please help me with this sling model for multifield with sightly

  • March 19, 2024
  • 2 replies
  • 1998 views
<panel
jcr:primaryType="nt:unstructured"
sling:resourceType="granite/ui/components/coral/foundation/form/multifield"
composite="{Boolean}true"
fieldLabel="Panels">
<field
jcr:primaryType="nt:unstructured"
sling:resourceType="granite/ui/components/coral/foundation/container"
name="./panels">
<items jcr:primaryType="nt:unstructured">
<column
jcr:primaryType="nt:unstructured"
sling:resourceType="granite/ui/components/coral/foundation/container">
<items jcr:primaryType="nt:unstructured">
<accordianIcon
jcr:primaryType="nt:unstructured"
sling:resourceType="/libs/granite/ui/components/coral/foundation/form/pathfield"
fieldDescription="icon to be displayed for expand/collapse option"
fieldLabel="Accordion Title Icon"
name="./iconreferenceclose"
rootPath="/content/dam"/>
<alttext
jcr:primaryType="nt:unstructured"
sling:resourceType="granite/ui/components/coral/foundation/form/textfield"
fieldDescription="A title to display as the headline Accordion."
fieldLabel="Alt Text"
name="./altText"/>
</items>
</column>
</items>
</field>
</panel>
This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.

2 replies

sateaswa94
Level 3
March 19, 2024

Step 1
create a Sling model for  accordion container

package com.example.models;
import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.models.annotations.Model;
import org.apache.sling.models.annotations.injectorspecific.SlingObject;

import org.apache.sling.models.annotations.DefaultInjectionStrategy;

import javax.inject.Inject;
import java.util.List;
@Model(adaptables = SlingHttpServletRequest.class, defaultInjectionStrategy = DefaultInjectionStrategy.OPTIONAL)
public class AccordionContainer {
@586265
private List<AccordionItem> accordionItems;
// Getters for the properties

public List<AccordionItem> getAccordionItems() {
return accordionItems;
}
}
Step 2
Create a sling model for accordion Item 

package com.example.models;

import org.apache.sling.api.resource.Resource;
import org.apache.sling.models.annotations.Model;
import org.apache.sling.models.annotations.DefaultInjectionStrategy;

import javax.inject.Inject;
import javax.inject.Named;

@Model(adaptables = Resource.class, defaultInjectionStrategy = DefaultInjectionStrategy.OPTIONAL)
public class AuthorModel {
@586265
@Named("iconreferenceclose")
private String iconReferenceClose;
@586265
private String altText;

public String getIconReferenceClose() {
return iconReferenceClose;
}
public String getAltText() {
return altText;
}
}
Step 3
Sightly code to access the multifield dialog
<sly data-sly-use.accordionContainer="com.example.models.AccordionContainer">

<ul>
<sly data-sly-list.accordionItem="${accordionContainer.accordionItems}">
<li>
<h3>${accordionItem.iconReferenceClose}</h3>
<p>${accordionItem.altText}</p>
</li>
</sly>
</ul>
</sly>

Level 2
March 19, 2024

IN step one you mention-- private List<AccordionItem> accordionItems;

what is this interface AccordionItem  ? and from which class need to extend can you please help?

sateaswa94
Level 3
March 20, 2024

Hi @shivamsh14  It is not an interface, AccordionItem is a separate sling model for the multifield items

HrishikeshKagne
Community Advisor
Community Advisor
March 20, 2024