0

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>
Dileepa
  • 1,019
  • 1
  • 15
  • 40

1 Answers1

1

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.

Vlad
  • 10,602
  • 2
  • 36
  • 38
  • Is there any particular design reason, for providing PageManager as implicit object and not allowing to invoke its methods with parameters ? – Dileepa Apr 13 '18 at 03:50
  • 1
    HTL does not allow calling methods with parameters because the original designers felt this would enforce a better separation of concern between the model/business-logic and the view/rendering template. A number of global objects are available from HTL in AEM to make it easier for developers to access commonly used properties (see https://helpx.adobe.com/experience-manager/htl/using/global-objects.html). Some of these however have APIs that require parameters for the methods, these are more suitable to be passed down to Use-Objects. – Vlad Apr 16 '18 at 08:01