Expand my Community achievements bar.

Radically easy to access on brand approved content for distribution and omnichannel performant delivery. AEM Assets Content Hub and Dynamic Media with OpenAPI capabilities is now GA.

my child tittle is not coming in list in sightly

Avatar

Level 2

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.

haritha6_0-1659959413457.png

 

***********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>

3 Replies

Avatar

Employee Advisor

 

<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

 

 

Avatar

Level 3

Hi @haritha6 ,

Please try updating the htl code as below

<div data-sly-list.title="${industryModel.childTitle}">

${title}

</div>

 

Reference: 

Thanks,

Anil.

 

Avatar

Community Advisor

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>