Get child node property from currentStyle object in sightly/ HTL | Community
Skip to main content
Level 2
September 27, 2024
Solved

Get child node property from currentStyle object in sightly/ HTL

  • September 27, 2024
  • 2 replies
  • 868 views

Hi All

i am trying to get a property from a child node of the currentStyle HTL object.

have the below structure

/etc/designs/abc

basepage(page component)

    |_

        header (property)

   

i am trying to get a property saved in header node in base page component html

Able to read property from currentStyle, which gives basepage path.

I am trying to get a property from the header node under basepage.

there is a getsubstyle method in the Style class. but not able to get that to work

Style (The Adobe AEM Quickstart and Web Application.)

TIA

 

 

 

 

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

You might not be able to do it with just HTL, since you cannot call methods which accepts some arguments in HTL. So, you will probably have to switch to a Sling model or a use js to get the intended style object.

2 replies

h_kataria
Community Advisor
h_katariaCommunity AdvisorAccepted solution
Community Advisor
September 27, 2024

You might not be able to do it with just HTL, since you cannot call methods which accepts some arguments in HTL. So, you will probably have to switch to a Sling model or a use js to get the intended style object.

EstebanBustamante
Community Advisor and Adobe Champion
Community Advisor and Adobe Champion
September 27, 2024

Hi,

 

The method getsubstyle(String relativePath) you are referring to requires an argument, relativePath; otherwise, it won't work. As explained by @h_kataria, you cannot invoke methods with parameters via HTL. The recommended approach is to use a Sling Model, where you can do something like this:

 

@Model(adaptables = Resource.class) public class MyModel { @ScriptVariable private Style currentStyle; @PostConstruct protected void init() { // Get the substyle Style subStyle = currentStyle.getSubStyle("/header"); // TODO: Get the properties from substyle or expose it directly to HTL }

 

Hope this helps

Esteban Bustamante