Top Thymeleaf Interview Questions (2021) | CodeUsingJava








Most frequently asked Thymeleaf Interview Questions


  1. What is Thymeleaf?
  2. Name some companies using Thymeleaf?
  3. What is Thymeleaf Template?
  4. How to check if list is empty using thymeleaf?
  5. What is a dialect in Thymeleaf?
  6. What is Thymeleaf fragment?
  7. How to loop through Map in Thymeleaf?
  8. What is Template Resolver in Thymeleaf?


What is Thymeleaf?

Thymeleaf can bring natural templates to our development workflow, it is a java based library that is used in creating web application.It is a server side mordern template engine that is used for development of web and standalone environments.
Thymeleaf provides support for serving XHTML/HTML5 in web applications.It converts our files into well formed XML files.It contains 6 types of templates given below:
XML
Valid XML
XHTML
Valid XHTML
HTML5
Legacy HTML5


Name some companies using Thymeleaf?

Companies that uses Thymeleaf are:
Enerko Informatik
Enonic
Lagerwey
PPI AG
Broadleaf Commerce
Auchan
Apereo CAS
Connect Group
Trabe


What is Thymeleaf Template?

Thymeleaf Template are locates in the custom directory as it is a Maven build file.It can directly open browsers and can display correct web pages.
Templates processed by the thymeleaf are HTML, XML, TEXT, etc.


How to check if list is empty using thymeleaf?

We can check if the list is empty by using the following code:

<div th:if="false">
 --content--
</div>


What is Thymeleaf fragment?

Thymeleaf fragment helps us in importing fragments of a template into another template.It is a small piece of code that can be included in another template.
It is used to create reusable, small components like the header, footer, navigation menu and other parts of a website that are repeated used on multiple pages.

What is a dialect in Thymeleaf?

By using dialect we can build layouts and resuable templates to improve the code reise.Thymeleaf dialect is good in Processing logic, Preprocessing & Postprocessing logic, and Expression objects.
There are 2 types of Thymeleaf Dialect are:
Custom dialects - By using this dialect we can build layouts.
Layout Dialects - It uses decorator pattern for working the layout files.


How to loop through Map in Thymeleaf?

We can loop through Map in Thymeleaf, by using the folowing code:
<tr th:each="instance : ">
    <td th:text="${instance.key}">keyvalue</td>
    <td th:text="${instance.value.numOfData}">num</td>
</tr>


What is Template Resolver in Thymeleaf?

A template resolver helps in resolving templates into TemplateResolution objects which contains information like template mode, caching, prefix and suffix of templates.It is reponsible for loading templates from a specific location.