Hi all,
Could you please direct me to a data sly call example with a tutorial that I could run and try out?
The concept is not very clear to me.
Appreciate all your replies.
Thanks,
RK.
Solved! Go to Solution.
Topics help categorize Community content and increase your ability to discover relevant content.
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’s say you want to create a reusable button template that you can call multiple times with different values.
/apps/myproject/components/content/mycomponent/
├── mycomponent.html
├── _button.html
└── .content.xml
_button.htmlThis is a reusable button component.
<!-- _button.html -->
<template data-sly-template.button="${@ text, link}">
<a href="${link}" class="btn btn-primary">${text}</a>
</template>
Here:
@ text, link are parameters.
${text} and ${link} are used inside the button.
mycomponent.htmlNow use data-sly-call to include the button in your component.
<!-- mycomponent.html -->
<sly data-sly-use.buttonTemplate="_button.html" />
<div>
<h2>Welcome to My Component</h2>
<!-- Call the template -->
<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:
data-sly-use.buttonTemplate="_button.html" loads the file with the template.
data-sly-call="${buttonTemplate.button @ ...}" invokes the template with parameters.
<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>
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.
data-sly-call?Avoids repetition.
Makes HTML cleaner and modular.
Easier to maintain.
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!
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’s say you want to create a reusable button template that you can call multiple times with different values.
/apps/myproject/components/content/mycomponent/
├── mycomponent.html
├── _button.html
└── .content.xml
_button.htmlThis is a reusable button component.
<!-- _button.html -->
<template data-sly-template.button="${@ text, link}">
<a href="${link}" class="btn btn-primary">${text}</a>
</template>
Here:
@ text, link are parameters.
${text} and ${link} are used inside the button.
mycomponent.htmlNow use data-sly-call to include the button in your component.
<!-- mycomponent.html -->
<sly data-sly-use.buttonTemplate="_button.html" />
<div>
<h2>Welcome to My Component</h2>
<!-- Call the template -->
<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:
data-sly-use.buttonTemplate="_button.html" loads the file with the template.
data-sly-call="${buttonTemplate.button @ ...}" invokes the template with parameters.
<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>
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.
data-sly-call?Avoids repetition.
Makes HTML cleaner and modular.
Easier to maintain.
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!
Views
Likes
Replies
Views
Likes
Replies