Hi! I have been asked in an interview that why sling model is needed when we can use Sightly to get property values directly?
Could someone please help me in answering this question in most understanding way possible?
Could someone please help me in answering this question in most understanding way possible?
Hello @vijayku8 ,
Here is my take on Sling Models.
For simple things like printing properties of a page, Sightly can surely be used and having a Sling Model in such situations will be redundant.
Sightly is a templating language and its primary purpose being "to display data". It does have some capability to calculate values and loop over lists, but as for any templating language, those capabilities are limited.
- In situations where additional conditions, code statements fetching data from another page/service is needed, using a Sling Model is a good choice.
- When we need Logic to format email addresses or format/validate date inputs or validate if the the file browsed is an asset or a page.
- Fetch data from a service/servlet to show rating/reviews, count of pages, breadcrumb, build navigation, and similar dynamic data related functionalities.
Some of the simple checks can be done in using Sightly frontend however, that would make the Sightly code difficult to debug and maintain at later stages of the project.
Using Sling Models, the code is kept clean and maintainable.
thanks,
Preetpal
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.