aemsightlyhtl

Sightly get Page object by path


Why the following code doesn't work in my component?

<sly data-sly-test.thatPage="${pageManager.getPage @path=properties.pagePath}" data-sly-unwrap>
      <div>${thatPage.getPath}</div>
</sly>

Solution

  • Because you cannot invoke methods with arguments/parameters in HTL expressions.

    Your best bet in this case is to create a helper Use-Object (either a POJO or a Sling Model) that allows passing the path when it's initialised and has a getter for the page corresponding to the path.