Thymeleaf
Encyclopedia
Thymeleaf is a Java
Java (programming language)
Java is a programming language originally developed by James Gosling at Sun Microsystems and released in 1995 as a core component of Sun Microsystems' Java platform. The language derives much of its syntax from C and C++ but has a simpler object model and fewer low-level facilities...

 XML
XML
Extensible Markup Language is a set of rules for encoding documents in machine-readable form. It is defined in the XML 1.0 Specification produced by the W3C, and several other related specifications, all gratis open standards....

/XHTML
XHTML
XHTML is a family of XML markup languages that mirror or extend versions of the widely-used Hypertext Markup Language , the language in which web pages are written....

/HTML5 template engine that can work both in web (Servlet-based) and non-web environments. It is better suited for serving XHTML/HTML5 at the view layer of MVC-based web applications, but it can process any XML file even in offline environments.

In web applications Thymeleaf aims to be a complete substitute for JSP
JSP
JSP may stand for:* Jake Shea's Parties* Joe Six-Pack, Attributed to Sarah Palin, 2008 vice presidential candidate* Ji-Sung Park, South Korean footballer* Jacketed, Soft Point, a type of bullet* Jackson Structured Programming* Japan Socialist Party...

, and implements the concept of Natural Templates: template files that can be directly open in browsers and that still display correctly as web pages.

Thymeleaf is Open-Source Software, licensed under the Apache License 2.0.

Features

From the project's website:
  • Java template engine for XML
    XML
    Extensible Markup Language is a set of rules for encoding documents in machine-readable form. It is defined in the XML 1.0 Specification produced by the W3C, and several other related specifications, all gratis open standards....

    , XHTML
    XHTML
    XHTML is a family of XML markup languages that mirror or extend versions of the widely-used Hypertext Markup Language , the language in which web pages are written....

     and HTML5.
  • Works both in web and non-web (offline) environments. No hard dependency on the Servlet API.
  • Based on modular feature sets called dialects.
    • Dialect features (e.g.: evaluation, iteration, etc.) are applied by linking them to template's tags and/or attributes.
    • Two dialects available out-of-the-box: Standard and SpringStandard (for Spring MVC apps, same syntax as Standard).
    • Developers can extend and create custom dialects.
  • Several template modes:
    • XML
      XML
      Extensible Markup Language is a set of rules for encoding documents in machine-readable form. It is defined in the XML 1.0 Specification produced by the W3C, and several other related specifications, all gratis open standards....

      : validating against a DTD
      Document Type Definition
      Document Type Definition is a set of markup declarations that define a document type for SGML-family markup languages...

       or not.
    • XHTML
      XHTML
      XHTML is a family of XML markup languages that mirror or extend versions of the widely-used Hypertext Markup Language , the language in which web pages are written....

       1.0 and 1.1
      : validating against standard DTD
      Document Type Definition
      Document Type Definition is a set of markup declarations that define a document type for SGML-family markup languages...

      s or not.
    • HTML5: both XML-formed code and legacy-based HTML5. Legacy non-XML code will be automatically cleaned and converted to XML
      XML
      Extensible Markup Language is a set of rules for encoding documents in machine-readable form. It is defined in the XML 1.0 Specification produced by the W3C, and several other related specifications, all gratis open standards....

       form.
  • Full (and extensible) internationalization support.
  • Configurable, high performance parsed template caché that reduces input/output to the minimum.
  • Automatic DOCTYPE translations –from template DTD
    Document Type Definition
    Document Type Definition is a set of markup declarations that define a document type for SGML-family markup languages...

     to result DTD– for (optional) validation of both template and result code.
  • Extremely extensible: can be used as a template engine framework if needed.
  • Complete documentation including several example applications.

Example

The following example produces an HTML5 table with rows for each item of a List variable called allProducts.















Name Price
Oranges 0.99



This piece of code includes:
  • Internationalization expressions: #{ ... }
  • Variable/model-attribute evaluation expressions: ${ ... }
  • Utility functions: #numbers.formatDecimal( ... )


Also, this fragment of (X)HTML code can be perfectly displayed by a browser as a prototype, without being executed at all: it is a natural template.

See Also

  • Template Engine (web)
  • JSP
    JavaServer Pages
    JavaServer Pages is a Java technology that helps software developers serve dynamically generated web pages based on HTML, XML, or other document types...

  • Spring Framework
  • FreeMarker
    FreeMarker
    FreeMarker is a Java-based template engine focusing on the MVC software architecture. Although it's mostly used for Servlet-based Web Application development, it can be used for any other kind of text output, such as generating CSS, Java source code, etc. Unlike JSP, it is not dependent on the...

  • Apache Velocity

External Links

The source of this article is wikipedia, the free encyclopedia.  The text of this article is licensed under the GFDL.
 
x
OK