Object found in an htl file but don't know how it was imported | Community
Skip to main content
Level 3
October 26, 2023
Solved

Object found in an htl file but don't know how it was imported

  • October 26, 2023
  • 3 replies
  • 730 views

In an html file I can see a code like below.

{{@root.group.name}} - {{add.cityCode}}

I believe that 'add' is an object . But I cannot see a statament like data-sly-use.add=//some class name

 in the htl file. There is only a single occurrence of 'add' in the file. Could you please tell me how is it possible? Also I need to show a Item  add.cityZip if cityZip is not null (cityZip is a string a suppose that it can be null or empty). If it is empty I need to show {{@root.group.name}} - {{add.cityCode}} otherwise I 

need to show {{@root.group.name}} - {{add.cityZip}}-{{add.cityCode}}. could anyone share how can we use the if else here?

 

 
This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by EstebanBustamante

Because of the presence of the '@root' object, my initial assumption would be that the scripting language in use is Handlebars.js (https://handlebarsjs.com/api-reference/data-variables.html). However, it is possible that it could be any other JavaScript templating language utilizing 'root' as part of its syntax. Nonetheless, the use of '@root' strongly suggests the presence of an additional templating language alongside HTL. Most likely, this is compiled through JS. I recommend reviewing the code to identify any additional JS frameworks that your project might be utilizing.

 

Once you determine the specific framework, you can refer to the documentation of that framework to learn how to implement an if/else condition.

 

Hope this helps

3 replies

aanchal-sikka
Community Advisor
Community Advisor
October 26, 2023

@vineetham123 

 

Please check if your component is extending some other component via sling:resourceSuperType. 

In this case, it might be inheriting files via the parent component. The variable "add" might have been instantiated in inherited files.

Aanchal Sikka
EstebanBustamante
Community Advisor and Adobe Champion
EstebanBustamanteCommunity Advisor and Adobe ChampionAccepted solution
Community Advisor and Adobe Champion
October 26, 2023

Because of the presence of the '@root' object, my initial assumption would be that the scripting language in use is Handlebars.js (https://handlebarsjs.com/api-reference/data-variables.html). However, it is possible that it could be any other JavaScript templating language utilizing 'root' as part of its syntax. Nonetheless, the use of '@root' strongly suggests the presence of an additional templating language alongside HTL. Most likely, this is compiled through JS. I recommend reviewing the code to identify any additional JS frameworks that your project might be utilizing.

 

Once you determine the specific framework, you can refer to the documentation of that framework to learn how to implement an if/else condition.

 

Hope this helps

Esteban Bustamante
kautuk_sahni
Community Manager
Community Manager
October 30, 2023

@vineetham123 Did you find the suggestions from users helpful? Please let us know if more information is required. Otherwise, please mark the answer as correct for posterity. If you have found out solution yourself, please share it with the community.

Kautuk Sahni