Hi @bangar20
You can use Sling Model to get the parent Page object, and then use the page API from sightly to obtain such values.
Using constructor injection as the example below as this strategy can also reduce memory consumption of your application, https://sourcedcode.com/blog/aem/aem-sling-model-field-injection-vs-constructor-injection-memory-con...
Sightly:
<sly data-sly-use.mycomponent="com.mysite.models.components.MyComponent"></sly>
${mycomponent.properties['jcr:title']}
Sling Model:
import com.day.cq.wcm.api.Page;
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.ScriptVariable;
import javax.inject.Inject;
import javax.inject.Named;
@Model(adaptables = Resource.class,
defaultInjectionStrategy = DefaultInjectionStrategy.OPTIONAL)
public class MyComponent {
private Page absParentPage;
@Inject
public MyComponent(@ScriptVariable @Named("currentPage") final Page currentPage) {
Page parentPage = currentPage.getAbsoluteParent(2);
if (parentPage != null) {
absParentPage = parentPage;
}
}
public Page getAbsParentPage() {
return absParentPage;
}
}
Hope that helps!
Regards,
Santosh