What problem does it solve?
Liferay FreeMarker templates are powerful but easy to misuse; this guide reduces errors by showing how to access web content fields, use themeDisplay and serviceLocator safely, and apply null-safety and escaping to avoid runtime errors and XSS vulnerabilities.
Core Features & Use Cases
- Web Content Templates: Access structure fields, images, repeaters, and nested fields with safe null-checks.
- Application Display Templates (ADT): Render Asset Publisher and custom lists, parse article XML with saxReaderUtil, and produce contextual links.
- Fragments & Widget Templates: Use themeDisplay, layout and portal URLs, and lightweight macros for reusable presentation logic.
- Best Practices & Anti-Patterns: Recommendations to avoid heavy business logic, database calls, manual caching, and to prefer presentation-only templates with htmlUtil.escape for user data.
Quick Start
Create a FreeMarker template that outputs a web content field with a null-safety check and htmlUtil.escape, and demonstrate accessing themeDisplay and a service via serviceLocator.