Hi @rama_krishnany,
In HTL, data-sly-call is used to invoke a template (like a function) and pass parameters to it. This helps you re-use logic across your component’s HTML files.
Let me explain you using a simple real-world example
Let’s say you want to create a reusable button template that you can call multiple times with different values.
File Structure:
/apps/myproject/components/content/mycomponent/
├── mycomponent.html
├── _button.html
└── .content.xml
1. Create a template in _button.html
This is a reusable button component.
<template data-sly-template.button="${@ text, link}">
<a href="${link}" class="btn btn-primary">${text}</a>
</template>
Here:
2. Call the template in mycomponent.html
Now use data-sly-call to include the button in your component.
<sly data-sly-use.buttonTemplate="_button.html" />
<div>
<h2>Welcome to My Component</h2>
<sly data-sly-call="${buttonTemplate.button @ text='Visit Adobe', link='https://www.adobe.com'}" />
<sly data-sly-call="${buttonTemplate.button @ text='Google', link='https://www.google.com'}" />
</div>
Here:
Output (HTML Rendered)
<div>
<h2>Welcome to My Component</h2>
<a href="https://www.adobe.com" class="btn btn-primary">Visit Adobe</a>
<a href="https://www.google.com" class="btn btn-primary">Google</a>
</div>
How to try it?
-
Create a new component in your local AEM project.
-
Add the two HTML files (_button.html and mycomponent.html).
-
Use this component on a page in your local AEM instance.
-
Check the output in the browser.
Why use data-sly-call?
To deepen your understanding, consider exploring the following resources:
-
Getting Started with HTL: An introductory guide to HTL in AEM.
Getting Started with HTL
-
HTL Specification: Detailed documentation on HTL syntax and features.
HTL Specification
-
HTL Code Samples: Practical examples demonstrating various HTL features.
HTL Code Samples
-
Community Tutorial on data-sly-template and data-sly-call: A step-by-step guide with examples.
AEM data-sly-template and data-sly-call usage
This video tutorial demonstrates how to define and call templates in AEM:
Hope that helps!