Expand my Community achievements bar.

Don’t miss the AEM Skill Exchange in SF on Nov 14—hear from industry leaders, learn best practices, and enhance your AEM strategy with practical tips.
SOLVED

Child Page Properties multified access

Avatar

Level 3

Hi All,

                 How can we access child page properties multifield.

In my project we have created multifield in the page  properties  and i wanted to access in the navigation component and display it.

 

Kr,

Sanjay

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

Hi @savi50 ,

 

I think you can extend navigation component and in this path (/libs/core/wcm/components/navigation/v1/navigation/itemContent.html) we can add custom model to get your customised multifield page properties. For eg. like below

 

<template data-sly-template.itemContent="${@ item='The navigation item'}">
    <a href="${item.URL}" aria-current="${item.current && 'page'}"
       data-cmp-clickable="${item.data ? true : false}"
       class="cmp-navigation__item-link">${item.title}
	</a>
       <!--  /*extended code */ -->
	<sly data-sly-use.additionalProperties="${'com.test.model.CustomNavigationModel' @ path=item.path}">
		<p> ${additionalProperties.customProp} </p>
	</sly>
      <!--  /*extended code */ -->
</template>

//Additional Sling model

 

@Model(adaptables = {SlingHttpServletRequest.class}, defaultInjectionStrategy = DefaultInjectionStrategy.OPTIONAL)
public class CustomNavigationModel {
	
	@RequestAttribute(name = "path")
    private String path;
	
	@SlingObject
    private ResourceResolver resourceResolver;
	
	String customProp;
	
	@PostConstruct
	protected void init() {
		Resource resource = resourceResolver.resolve(path+ "/jcr:content");
		ValueMap vm = resource.adaptTo(ValueMap.class);
		String[] customProps = vm.get("sling:vanityPath", String[].class);
if(customProps!=null) {
customProp = Arrays.toString(customProps);
} } public String getCustomProp() { return customProp; } }

View solution in original post

2 Replies

Avatar

Community Advisor

Hi @savi50 

 

Please find my blog where I have explained about accessing the multi field https://allaembykiran.wordpress.com/2021/01/13/nested-multi-field/

 

Hope this helps!

 

Thanks,

Kiran Vedantam.

Avatar

Correct answer by
Community Advisor

Hi @savi50 ,

 

I think you can extend navigation component and in this path (/libs/core/wcm/components/navigation/v1/navigation/itemContent.html) we can add custom model to get your customised multifield page properties. For eg. like below

 

<template data-sly-template.itemContent="${@ item='The navigation item'}">
    <a href="${item.URL}" aria-current="${item.current && 'page'}"
       data-cmp-clickable="${item.data ? true : false}"
       class="cmp-navigation__item-link">${item.title}
	</a>
       <!--  /*extended code */ -->
	<sly data-sly-use.additionalProperties="${'com.test.model.CustomNavigationModel' @ path=item.path}">
		<p> ${additionalProperties.customProp} </p>
	</sly>
      <!--  /*extended code */ -->
</template>

//Additional Sling model

 

@Model(adaptables = {SlingHttpServletRequest.class}, defaultInjectionStrategy = DefaultInjectionStrategy.OPTIONAL)
public class CustomNavigationModel {
	
	@RequestAttribute(name = "path")
    private String path;
	
	@SlingObject
    private ResourceResolver resourceResolver;
	
	String customProp;
	
	@PostConstruct
	protected void init() {
		Resource resource = resourceResolver.resolve(path+ "/jcr:content");
		ValueMap vm = resource.adaptTo(ValueMap.class);
		String[] customProps = vm.get("sling:vanityPath", String[].class);
if(customProps!=null) {
customProp = Arrays.toString(customProps);
} } public String getCustomProp() { return customProp; } }