Expand my Community achievements bar.

SOLVED

Get child node property from currentStyle object in sightly/ HTL

Avatar

Level 2

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

 

 

 

 

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

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.

View solution in original post

2 Replies

Avatar

Correct answer by
Community Advisor

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.

Avatar

Community Advisor

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