Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

SOLVED

Child Page Properties multified access

savi50
Level 2
Level 2

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
kishorekumar14
Correct answer by
Level 9
Level 9

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
Kiran_Vedantam
Community Advisor
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.

kishorekumar14
Correct answer by
Level 9
Level 9

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