Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
package com.aem.project.core.models;
import com.day.cq.wcm.api.Page;
import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.models.annotations.DefaultInjectionStrategy;
import org.apache.sling.models.annotations.Model;
import org.apache.sling.models.annotations.injectorspecific.RequestAttribute;
import org.apache.sling.models.annotations.injectorspecific.ScriptVariable;
import org.apache.sling.models.annotations.injectorspecific.SlingObject;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
@Model(adaptables = SlingHttpServletRequest.class,defaultInjectionStrategy = DefaultInjectionStrategy.OPTIONAL)
public class HelloWorldModel {
@SlingObject
private Resource resource;
@RequestAttribute
private String pageTitle;
@ScriptVariable
private Page currentPage;
@RequestAttribute(name = "pageNae")
private String name;
public String getPageTitle() {
return pageTitle;
}
public String getName() {
return name;
}
public String getPath() {
return resource.getPath();
}
public Map<String, String> getMap() {
Map<String,String> map = new HashMap<>();
Iterator<Page> iterator = currentPage.listChildren();
while (iterator.hasNext())
{
Page child = iterator.next();
map.put(child.getName(),child.getPath());
}
return map;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment