How to read inheritedPageProperties in sling models? | Community
Skip to main content
Level 3
July 29, 2021
Solved

How to read inheritedPageProperties in sling models?

  • July 29, 2021
  • 2 replies
  • 3023 views

I would like to show the boolean values in my showIcon property based on the text in my title property. 

 

I added below code in my local to read inherited page properties but it didn't work. 

textModel.showIcon is showing false even though when I author "some text" words in extitle dialog

My HTL code:

 

<div class="test">
<svg aria-hidden="true" class="test-icon -test-team"
data-sly-test="${inheritedPageProperties.Icon || textModel.showIcon}">
</svg>
<span class="test-copy-text">
${inheritedPageProperties.extitle}
</span>
</div>

 My sling model code:

 

 

 

private InheritanceValueMap pageProperties; @ScriptVariable private Page currenPage; public boolean isShowIcon() { return showIcon; } @PostConstruct protected void init() { InheritanceValueMap ivm = new HierarchyNodeInheritanceValueMap(currenPage.getContentResource()); String inheritedValueCustomProperty = ivm.getInherited("extitle", String.class); if(inheritedValueCustomProperty !=null){ if(inheritedValueCustomProperty.contains("some text")) showIcon = true; } }

 

 

 

 

Or 

Sling model 

 

public boolean isShowIcon() {
return showIcon;
}

private boolean showIcon;

if(pageProperties !=null){
String copyrightText1 = pageProperties.get( "extitle", "" );
if(copyrightText1.contains("some text"))
showIcon = true;
}

 

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.

2 replies

Love_Sharma
Love_SharmaAccepted solution
Level 4
July 29, 2021
BrianKasingli
Community Advisor and Adobe Champion
Community Advisor and Adobe Champion
July 29, 2021

@ramaem12,

your code looks alright, no problems here. Can you share with us your page structure?