legacy-knowledge-base
公開されました Jul. 2, 2025

UI での Freemarker テンプレート エラーの処理

written-by

Katlyn Lee

How To articles are not official guidelines or officially supported documentation. They are community-contributed content and may not always reflect the latest updates to Liferay DXP. We welcome your feedback to improve How To articles!

While we make every effort to ensure this Knowledge Base is accurate, it may not always reflect the most recent updates or official guidelines.We appreciate your understanding and encourage you to reach out with any feedback or concerns.

legacy-article

learn-legacy-article-disclaimer-text

問題

  • Liferay は、特に Web コンテンツ テンプレートが Web コンテンツ構造から存在しない値を参照する場合に、UI で Freemarker テンプレート エラーをレンダリングします。 これにより、管理者以外のユーザーがサイトにアクセスする際に、混乱やマイナスのユーザー エクスペリエンスが生じる可能性があります。

Freemarker_Error.png

Environment

  • ライフレイ DXP 7.0 - 7.3

解決策

Freemarker テンプレートを作成するときは、https://freemarker.apache.org/docs/ref_directive_attempt.html で説明されいるように、試行ブロックと回復ブロックを実装します。 これにより、テンプレート変数が存在しない場合に、ユーザー フレンドリーなエラーを UI に表示できます。 以下に例を示します。

Test Content:
<#attempt>
  Company Name: ${companyName}
<#recover>
  Unable to retrieve Company Name.
</#attempt>

companyName 変数が存在しない場合 (またはその場所で他のエラーが発生した場合)、出力は次のようになります。

テスト コンテンツ:
会社名を取得できません。

companyName 変数が存在し、その値が Liferayの場合、出力は次のようになります。

テスト内容:

追加情報

Freemarker テンプレートをブラウザ コンソールまたは Liferay ログのみに表示し、よりユーザー フレンドリーなエラー メッセージを代わりに UI に表示する機能リクエスト チケットが作成されました。 詳細については、 LPS-119835 を参照してください。

did-this-article-resolve-your-issue

legacy-knowledge-base