liferay-freemarker

Create and debug FreeMarker templates for Liferay web content and display components.

Updated Aug 27, 2026
One-click install
npx skills add https://github.com/JoaoPedroAmaral/backBarbearia --skill liferay-freemarker
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: liferay-freemarker
Source: https://github.com/JoaoPedroAmaral/backBarbearia/tree/main/.claude/skills/liferay-freemarker
Command: npx skills add https://github.com/JoaoPedroAmaral/backBarbearia --skill liferay-freemarker

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

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.

Frequently Asked Questions about liferay-freemarker

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I access web content fields in Liferay FreeMarker templates without runtime errors?

Access web content fields in Liferay FreeMarker templates by applying null-safety checks before rendering structure fields, images, repeaters, and nested fields. This prevents runtime errors when expected data is missing or unset in your web content structures.

How does saxReaderUtil work for parsing article XML in Application Display Templates?

saxReaderUtil parses article XML directly within Application Display Templates to extract and render specific content elements from Asset Publisher and custom lists. It enables contextual link generation and precise asset rendering in server-rendered views.

Can I use serviceLocator and themeDisplay in Liferay widget templates and fragments?

serviceLocator and themeDisplay are accessible in Liferay widget templates and fragments to retrieve portal URLs, layout details, and lightweight services. Use them safely to support reusable presentation logic without embedding heavy business logic.

What is the best way to prevent XSS vulnerabilities in Liferay FreeMarker templates?

Prevent XSS vulnerabilities in Liferay FreeMarker templates by applying htmlUtil.escape to all user-generated data and web content fields before output. Ensure templates remain presentation-only, avoiding manual caching and direct database calls.

Why does my Liferay FreeMarker template fail when rendering nested structure fields?

Liferay FreeMarker templates fail when rendering nested structure fields if null-safety checks are missing. Validate the existence of nested fields, repeaters, and images before accessing them to avoid unexpected template processing interruptions.

Do I need FreeMarker macros for Liferay web content templates and fragments?

FreeMarker macros are recommended for Liferay web content templates and fragments to encapsulate reusable presentation logic. They help maintain clean, presentation-only templates while handling themeDisplay, layout URLs, and safe HTML escaping consistently.