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

Asset Publisher とカスタム表示テンプレートを使用して、Web コンテンツ記事に適用された画像をレンダリングする

written-by

Laura Li

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

問題

  • カスタム表示テンプレートを使用して Asset Publisher に表示される Web コンテンツ記事で適応画像を使用するにはどうすればよいですか?

Environment

  • Liferay DXP 7.3

解決策

  1. System Settings > Template Engines > Freemarker Engine > Restricted Classes に移動し、制限されたクラスから serviceLocator を削除します。
  2. Asset Publisher テンプレートの先頭に、次のコードを追加します。
    <#assign dlAppServiceUtil = serviceLocator.findService("com.liferay.document.library.kernel.service.DLAppService")/>
  3. 画像を取得するときは、次のコードを使用します。

    <@adaptive_media_image["img"] fileVersion=dlAppServiceUtil.getFileEntry(image_json.getLong('fileEntryId')).getFileVersion()/>

Asset Publisher でカスタム テンプレートを適用すると、ソース コードには以下のように適用されたイメージが含まれます。

<picture data-fileentryid="39919">
<source media="(max-width:300px)" srcset="/o/adaptive-media/image/39919/Thumbnail-300x300/liferay-product-downloads.png?t=1635486233174">
<source media="(max-width:1000px) and (min-width:300px)" srcset="/o/adaptive-media/image/39919/Preview-1000x0/liferay-product-downloads.png?t=1635486233174">
<img src="http://localhost:8080/documents/37244/0/liferay-product-downloads.png/380248bb-8067-e93d-2468-1a5b22f16f48?version=1.0&amp;t=1635486233174">
</picture>

did-this-article-resolve-your-issue

legacy-knowledge-base