Skip to content

Instantly share code, notes, and snippets.

@sgaem
Created January 2, 2019 15:00
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save sgaem/d912358c2a3aec83f96f5a129872ba6c to your computer and use it in GitHub Desktop.
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