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
Solved! Go to Solution.
Views
Replies
Total Likes
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; } }
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.
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; } }
Views
Likes
Replies
Views
Likes
Replies