Adobe Experience Manager (AEM) released version 6.5 on April 8, 2019. HTML Template Language (HTL) version 1.4 is part of this release. It’s a great web framework that increases security. It’s also easy to understand for non-Java developers. Here are AEM HTL 3 new features, that I find exciting in HTL 1.4 and you should start implementing them today.

SPONSORED LINKS

1.3 new features of HTL introduced from AEM 6.5

With the release of AEM 6.5, HTL version is also updated to 1.4.

Following are the 3 features in HTL 1.4 that are most exciting to me.

1.1.Feature 1: data-sly-set for variable declaration

This has been long due for us developers. Now you can store a value in a variable and use it anywhere after it has been declared.

example: let’s say we are creating a page which lists down various features of a car. Attribute ‘model’ might be something that would get used many times. We can store it in a variable and then use it elsewhere.

<!--/* define and set variable 'model' */-->
<div data-sly-set.model="${myCar.model}">some content</div>
<!--/* use 'model' variable anywhere */-->
<div>My car model: ${model}</div>

1.2.Feature 2: Using ‘in’ as a relational operator in strings, arrays, lists, objects and maps

Keyword ‘in’ can now be used as a relational operator in strings, arrays, lists, objects and maps.

string: to check if a string is contained in another string

example:

<!--/* below code will return true */-->
${'h' in 'hello world'}
<!--/* below code will return false*/-->
${'q' in 'hello world'}
<!--/* the check is case-sensitive, so the below code will return false */-->
${'H' in 'hello world'}

array or list: to check if array or list contains the attribute

example:

<!--/* if someArray has [1, 2, 3, 4, 5] then below code will return true */-->
${1 in someArray}
<!--/* if someArray has [1, 2, 3, 4, 5] then below code will return false */-->
${6 in someArray}

object or map: to check if object or map has the property

example:

<!--/* if myObject has a property 'color' then below code will return true */-->
${'color' in myObject}
<!--/* if myObject has a property 'color' then below code will return false */-->
${'blue' in myObject}

1.3.Feature 3: data-sly-list and data-sly-repeat now have control parameters: begin, step, end

Now we can use control parameters in data-sly-list and data-sly-repeat

begin – iteration begins at the item located at the specified index; the first item of the collection has index 0
step – iteration will only process every step items of the collection, starting with the first one
end – iteration ends at the item located at the specified index (inclusive)

example:

<!--/* if you want to first 5 elements of the list */-->
<ul data-sly-list="${currentPage.listChildren @ begin = 0, end = 4}">
    <li>${item.title}</li>
</ul>
<!--/* if you want to see from 5th to 10th element */-->
<div data-sly-repeat="${currentPage.listChildren @ begin = 4, end = 9}">
    <div>${item.title}</div>
</div>

SPONSORED LINKS

Do you face issues while trying to download assets for your local environment? Disk-space constraints? keeping them up-to-date?

Here’s a neat trick: How to show AEM images in your local environment from a different server

2.Extra new features in HTL 1.4

Besides these 3 enhancements there are other 2 updates. These are simple enough to understand. I encourage you to try them out.

  1. Identifier for data-sly-unwrap
  2. Support for negative numbers

You can also read AEM 6.5 release notes here

SPONSORED LINKS

3.Conclusion

These enhancements are not a huge change but will make the developer lives a little bit easier.

Me personally, I like ‘in’ relational operator enhancement the best and have already started using it.

3.1.Which one are you going to implement first? let me know in the comments below.

As always, let me know if you have any questions or queries.

Leave a Reply

Your email address will not be published. Required fields are marked *

Contributed by Raman Broach
I am an Enterprise Architect by role and Developer by heart, have been working in I.T. for more than 15 years now.
My Area of expertise - AEM (Adobe Experience Manager) and Java.
My Area of philosophy - Shooting for the moon so that I can miss and be amongst the stars.

for suggestions and contributions, kindly contact us