Converting jsp to HTL

Avatar

Avatar
Validate 1
Level 2
srikanthg212933
Level 2

Likes

4 likes

Total Posts

37 posts

Correct reply

1 solution
Top badges earned
Validate 1
Ignite 1
Give Back 5
Give Back 3
Give Back
View profile

Avatar
Validate 1
Level 2
srikanthg212933
Level 2

Likes

4 likes

Total Posts

37 posts

Correct reply

1 solution
Top badges earned
Validate 1
Ignite 1
Give Back 5
Give Back 3
Give Back
View profile
srikanthg212933
Level 2

22-09-2020

Hi I am trying to convert my existing jsp to htl. I am stuck at preparing valuemapresource which was included in jsp like below

ValueMap vm= new ValueMapDecorator(new HashMap<>());
vm.put("granite:class", "classname");
vm.put("value", value);
vm.put("name", name);
vm.put("text", text);
ValueMapResource valueMapResource = new ValueMapResource(resourceResolver, resource.getPath(), "granite/ui/components/coral/foundation/form/checkbox", vm);
<sling:include resource="<%= valueMapResource %>"/>

 I wanted to convert this above snippet to HTL using data-sly-resource. could you let me know how can i be able to prepare this similar resource in htl.

Accepted Solutions (1)

Accepted Solutions (1)

Avatar

Avatar
Establish
MVP
Anudeep_Garnepudi
MVP

Likes

275 likes

Total Posts

320 posts

Correct reply

87 solutions
Top badges earned
Establish
Ignite 1
Give Back 5
Give Back 3
Give Back 10
View profile

Avatar
Establish
MVP
Anudeep_Garnepudi
MVP

Likes

275 likes

Total Posts

320 posts

Correct reply

87 solutions
Top badges earned
Establish
Ignite 1
Give Back 5
Give Back 3
Give Back 10
View profile
Anudeep_Garnepudi
MVP

23-09-2020

Hi Srikanth,

 

HTL is strictly presentation layer. There is no way to create objects or write any logic  in HTL. You need a support class(Sling Model or Use class) to return ValueMapResource object. The returned object can be included in HTL.

 

-AG

Answers (2)

Answers (2)

Avatar

Avatar
Boost 5
Level 2
abhilakhpatre1
Level 2

Likes

8 likes

Total Posts

7 posts

Correct reply

1 solution
Top badges earned
Boost 5
Boost 3
Boost 1
Affirm 1
View profile

Avatar
Boost 5
Level 2
abhilakhpatre1
Level 2

Likes

8 likes

Total Posts

7 posts

Correct reply

1 solution
Top badges earned
Boost 5
Boost 3
Boost 1
Affirm 1
View profile
abhilakhpatre1
Level 2

22-09-2020

You can simply create a node in crx/de of required resource type (here : "granite/ui/components/coral/foundation/form/checkbox") . You can add the properties to node, like here you're putting it in ValueMap and  you can include that resource using data-sly-resource HTL syntax like below :

 

<div data-sly-resource="path/to/resource"></div>

For more ways to include resources using HTL please refer : https://docs.adobe.com/content/help/en/experience-manager-htl/using/htl/block-statements.html#resour... 

Avatar

Avatar
Validate 1
MVP
raj_mandalapu
MVP

Likes

125 likes

Total Posts

203 posts

Correct reply

72 solutions
Top badges earned
Validate 1
Contributor
Shape 1
Give Back 5
Give Back 3
View profile

Avatar
Validate 1
MVP
raj_mandalapu
MVP

Likes

125 likes

Total Posts

203 posts

Correct reply

72 solutions
Top badges earned
Validate 1
Contributor
Shape 1
Give Back 5
Give Back 3
View profile
raj_mandalapu
MVP

22-09-2020

You need to create a java class for this. if you are looking to populate dropdown then the below article may help you.

http://www.coderss.in/how-to-create-dropdown-dynamically-using-granite-datasource-object-in-aem-6-3/