Hi
I written the below sightly and below java code
my requirement is that my level 1 child tittle should come as list but it coming as paragraph, as shown below.
***********JAVA CODE**********
import java.util.ArrayList;
import java.util.Iterator;
import javax.annotation.PostConstruct;
import javax.inject.Inject;
import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.models.annotations.DefaultInjectionStrategy;
import org.apache.sling.models.annotations.Model;
import org.apache.sling.models.annotations.Via;
import org.apache.sling.models.annotations.injectorspecific.Self;
import org.apache.sling.models.annotations.injectorspecific.SlingObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.day.cq.wcm.api.Page;
import com.day.cq.wcm.api.PageFilter;
import com.day.cq.wcm.api.PageManager;
import com.te.aem.sling.model.IndustryModel;
@Model(adaptables = SlingHttpServletRequest.class,
adapters = IndustryModel.class,
defaultInjectionStrategy = DefaultInjectionStrategy.OPTIONAL)
public class IndustryModelImpl implements IndustryModel {
private static final Logger logger = LoggerFactory.getLogger(IndustryModelImpl.class);
Page childPage;
//String childTitle;
@inject
@Via("resource")
private String linkLabel;
@inject
@Via("resource")
private String linkPath;
@inject
private String childTitle;
@SlingObject
ResourceResolver resourceResolver;
@Deleted Account
SlingHttpServletRequest request;
@Override
public String getLinkLabel() {
return linkLabel;
}
@Override
public String getLinkPath() {
// TODO Auto-generated method stub
return linkPath;
}
@Override
public ArrayList<String> getChildTitle() {
//String children = linkPath;
ResourceResolver resourceResolver = request.getResourceResolver();
PageManager pageManager = resourceResolver.adaptTo(PageManager.class);
//ArrayList pageList = new ArrayList();
Page rootPage = pageManager.getPage(linkPath);
logger.info("rootPage === ++++++++++++ " + rootPage);
//Page rootPage = linkPath;
Iterator<Page> rootPageIterator = rootPage.listChildren(new PageFilter(false, false), false);
ArrayList<String> childTitles = new ArrayList<String>() ;
while(rootPageIterator.hasNext())
{
childPage = rootPageIterator.next();
childTitle = childPage.getTitle();
childTitles.add(childTitle) ;
logger.info("childTitle inside init === "+childTitle);
//pageList.add(path);
}
return childTitles ;
}
@PostConstruct
protected void init() {
}
}
***************SIGHTLY CODE******
<sly data-sly-use.industryModel="com.aem.sling.model.IndustryModel">
<h2>Haritha test :${industryModel.linkPath}</h2>
<div>
<li>
${industryModel.childTitle}
</li>
<div data-sly-list="${industryModel.childTitle}">
</div>
</div>
Views
Replies
Total Likes
<sly data-sly-use.industryModel="com.aem.sling.model.IndustryModel"> <h2>Haritha test :${industryModel.linkPath}</h2> <ul data-sly-list="${industryModel.childTitle}"> <li>${item}</li> </ul> </sly>
Your syntax is worng, try above
Hi @haritha6 ,
Please try updating the htl code as below
<div data-sly-list.title="${industryModel.childTitle}">
${title}
</div>
Reference:
Thanks,
Anil.
Use below way to print title of all child pages:
<sly data-sly-use.industryModel="com.aem.sling.model.IndustryModel">
<h2>${industryModel.linkPath}</h2>
<ul data-sly-list="${industryModel.childTitle}">
<li>${item}</li> //gives title of all child pages as it is the current item in the iteration.
</ul>
</sly>
Views
Likes
Replies
Views
Likes
Replies
Views
Likes
Replies