How to identify a Page Template using Freemarker

Issue

  • I need to identify if the current page is a page template or not, using Freemarker from the applied theme.
  • Is there a method similar to Layout.isPublicLayout() to achieve this?

Environment

  • Liferay DXP 7.2
  • Liferay DXP 7.3

Resolution

  • Unfortunately there is no direct method available such as isPublicLayout(), however, we can use the  fetchLayoutPageTemplateEntryByPlid method to achieve this.
  • Here is a code example to do it:
    <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>
¿Fue útil este artículo?
Usuarios a los que les pareció útil: 0 de 0