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

Freemarker を使用してページ テンプレートを識別する方法

written-by

Daniel Mijarra

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

問題

  • 適用されたテーマの Freemarker を使用して、現在のページがページ テンプレートであるかどうかを識別する必要があります。
  • これを達成するために Layout.isPublicLayout() に似た方法はありますか?

Environment

  • Liferay DXP 7.2
  • Liferay DXP 7.3

解決策

  • 残念ながら、 isPublicLayout()などの直接的なメソッドはありませんが、 fetchLayoutPageTemplateEntryByPlid メソッドを使用してこれを実現できます。
  • これを行うコード例を次に示します。
    <div id="wrapper" role="main">
    <#assign layout = themeDisplay.getLayout()/>
    <#assign plid = layout.getPlid() />

    <!-- Note that the page template could be a Draft -->
    <#if layout.getClassNameId() != 0>
    <#assign realPlid = layout.getClassPK()/>
    <#else>
    <#assign realPlid = plid/>
    </#if>

    <#assign layoutPageTemplateEntryLocalService = serviceLocator.findService("com.liferay.layout.page.template.service.LayoutPageTemplateEntryLocalService") />
    <#if layoutPageTemplateEntryLocalService.fetchLayoutPageTemplateEntryByPlid(realPlid)??>
    Template
    <#elseif layout.isPublicLayout() >
    Public
    <#else>
    Private
    </#if>
    </div>
did-this-article-resolve-your-issue

legacy-knowledge-base