問題
- 適用されたテーマの 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>