In AEM6.3 there are a number of new HTL features that I will outline in this article.

Number/Date-formatting

You have now native formatting of numbers and dates, no need anymore for writing custom code for this, also timezone and locale are supported.

Example:

<h2>${ 'dd-MMMM-yyyy hh:mm:ss' @
           format=currentPage.lastModified,
           timezone='PST',
           locale='fr'}</h2>

<h2>${ '#.00' @ format=300}</h2>

In the examples you see that the format is specified first, then the value you want to format.

Full details on the format you can use, are in the HTL-specification.

data-sly-use with resources

You can now get resources directly in HTL with data-sly-use, meaning you don’t have to write code just to get the resource.

Example:

<div data-sly-use.product=“/etc/commerce/product/12345”>
  ${ product.title }
</div>

Request-attributes

In the data-sly-include and data-sly-resource you can now pass requestAttributes in order to use them in the receiving HTL-script.

This way to can properly pass-in parameters into scripts / components.

<sly data-sly-use.settings="com.adobe.examples.htl.core.hashmap.Settings" 
        data-sly-include="${ 'productdetails.html' @ requestAttributes=settings.settings}" />

Java-code of the Settings class, the Map is used to pass in the requestAttributes:

public class Settings extends WCMUsePojo {

  // used to pass is requestAttributes to data-sly-resource
  public Map<String, Object> settings = new HashMap<String, Object>();

  @Override
  public void activate() throws Exception {
    settings.put("layout", "flex");
  }
}

Via a Sling-Model for example you can consume the value of the specified requestAttributes, in this “layout” is injected via the Map from the Use-class.

@Model(adaptables=SlingHttpServletRequest.class)
public class ProductSettings {
  @Inject @Optional @Default(values="empty")
  public String layout;

}

Fix for @extension

The @extension is now working in all scenarios, before you could have a result like “www.adobe.com.html”

Now the @extension checks whether to add or not add the extension.

No reason to not use it

${ link @ extension = 'html' }

Conclusion

These are the HTL-features added in AEM6.3, I hope this will make your programming-life easier 🙂

You can find more example on my github: https://github.com/heervisscher/htl-examples

@heervisscher

0 comments