DEV Community

pazvanti
pazvanti

Posted on

Phoenix - a modern template engine for Spring

After several months of work, it's time for me to present my most ambitious open-source project. It's not finalized yet; there are still bugs and features that need to be added, but it's stable enough for you to "play" with and give your feedback.

What is Phoenix?

Phoenix is a modern template engine for Spring and Spring Boot aiming to facilitate the development of complex web applications by providing a way to create complex and modular templates benefiting from server-side rendering for better integration between the frontend and backend.

Phoenix vs Thymeleaf or Freemarker

Phoenix offers several advantages compared to other existing template engines at the moment:

  • The ability to integrate Java code directly into HTML templates without needing to learn a new syntax or special utilities.

  • An easier-to-understand syntax that only requires a special character "@" to integrate Java code into HTML code.

  • Fragments or components that can be combined and reused, making the code easier to maintain.

  • Speed, speed, speed - Phoenix templates are compiled, offering rendering speeds up to 10x faster compared to Thymeleaf.

  • A single PhoenixController that easily allows the return of both HTML pages and JSON responses.

  • Reverse routing - a completely new feature for Spring. URLs are written at runtime in templates, eliminating the need for manual writing. You only mention the controller and method, and Phoenix calculates the correct URL. This way, you can change the URL in the controller without having to modify the template.

  • Pages dynamically modified by calling from JS to the backend to obtain a ready-to-add fragment/module to the DOM.

  • Easy to configure* (Work in Progress to reduce necessary dependencies).

Why Phoenix and not React/Angular/Vue?

Phoenix is not intended to be a replacement for JS frameworks. Instead, Phoenix aims to utilize existing JS frameworks to add SSR, thereby enhancing page rendering speed and FE-BE integration. You no longer need to always return complex JSON; you can directly provide an HTML page with everything needed and nothing more. There can be a whole debate about SSR vs non-SSR, so Phoenix tries to combine the advantages of both.

Open Source

Phoenix is open source, and everyone is encouraged to download the code, contribute improvements, or suggest features.

Source code: https://gitlab.com/ppopescu/phoenix-template-engine

Wiki: https://gitlab.com/ppopescu/phoenix-template-engine/-/wikis/home

Build jar: https://gitlab.com/ppopescu/phoenix-template-engine/-/jobs/5879024082/artifacts/download?file_type=archive

My blog: https://petrepopescu.tech

Top comments (0)