Fetch the date property from the page

Avatar

Avatar

maryanilak48011

Avatar

maryanilak48011

maryanilak48011

10-09-2020

How can I get the publication date property and the Image property from this page in sling model

maryanilak48011_0-1599753348441.png

 

View Entire Topic

Avatar

Avatar

ChitraMadan

MVP

Avatar

ChitraMadan

MVP

ChitraMadan
MVP

10-09-2020

Hi @maryanilak48011 ,

 

You can do something like below

 

@Getter
@Setter
@Model(adaptables = Resource.class, defaultInjectionStrategy = DefaultInjectionStrategy.OPTIONAL)
public class SampleModel {
 
@SlingObject
private transient ResourceResolver resourceResolver;

@PostConstruct
public void init() {
 
Resource requiredResource = resourceResolver.getResource("path of the page");
String publicationDate =requiredResource.getValueMap().get("publicationDate", String.class);
 
}