Assign a Display Page Templates to multiple Web content after migrating from a previous version of DXP 7.1


  • In versions prior to 7.1 there were no Display Page Templates to use with web contents.
  • After migrating to 7.1+, we can create a default Display Page Template associated to an existing web content structure from Design > Page Templates > Display Page Templates.
  • If we edit an existing web content with that structure, we see that it points to the default Display Page Template, but the relation will only be effective if we save the web content.
  • Is there a way to avoid this manual work and massively change the Display Page Template of migrated web contents?


  • DXP 7.1 or higher


  • To avoid manually changing each web content, we can write a Groovy a script using this API method (source):
    addAssetDisplayPageEntry(long userId, long groupId, long classNameId, long classPK, long layoutPageTemplateEntryId, int type, com.liferay.portal.kernel.service.ServiceContext serviceContext)
  • Important: The following pieces of Groovy code are intended as a starting guide and are not officially supported. They should be carefully reviewed and adapted for each use case. A database backup should be made before executing any code, as the changes are not revertible.
  • The first step would be to get the userId and classNameId
    // We are using the current user running the script but it could be another admin user.
    // Documentation:
    def userId = Long.valueOf(userInfo.get(''));
    def classNameId = PortalUtil.getClassNameId(JournalArticle.class.getName());
  • The next step would be getting the necessary JournalArticleResources for the web contents to modify.
    List<JournalArticleResource> journalArticleResources =
    JournalArticleResourceLocalServiceUtil.getJournalArticleResources(-1, -1);
    Note: If you have a lot of articles, in order to maintain performance please make sure you paginate your call to this service using a count method, for example:
    JournalArticleLocalServiceUtil.getStructureArticlesCount(long groupId, String ddmStructureKey)
  • Finally, for each journalArticleResource:
    • Get the associated groupId and resourcePrimKey
         def groupId = journalArticleResource.getGroupId();
         def resourcePrimKey = journalArticleResource.getResourcePrimKey();
    • Choose the layoutPageTemplateId and type, which can be the same for all journalArticleResources or different for each one:
         // We are assigning a default display page template relationships, hence TYPE_DEFAULT, so we also use 0L for layoutPageTemplateEntryId
         // If other types are used, such as TYPE_SPECIFIC, query the table layoutpagetemplateentry for the value of layoutPageTemplateEntryId associated to a particular display page template.
         def type = AssetDisplayPageConstants.TYPE_DEFAULT;
         def layoutPageTemplateEntryId = 0L;
    • Obtain the existingassetDisplayPageEntry, that is the Display Page Template, and add assign a new one:
         AssetDisplayPageEntry assetDisplayPageEntry = AssetDisplayPageEntryLocalServiceUtil.fetchAssetDisplayPageEntry(groupId, classNameId, resourcePrimKey);
         if (assetDisplayPageEntry == null) {
            AssetDisplayPageEntryLocalServiceUtil.addAssetDisplayPageEntry(userId, groupId, classNameId, resourcePrimKey, layoutPageTemplateEntryId, type, new ServiceContext());
  • Reminder: Please carefully review this code to adapt it to the particular use case and create a database backup before execution.

Additional Information

  • Liferay DXP 7.4 doesn't require making any changes. After the implementation of the feature request LPS-122275 (see Breaking Change documentation), entries in the table assetdisplaypageentry are not needed to use the default Display Page Template.
  • A problem affecting the Basic Web Content structure in the Global site, impacting the use of friendly URLs, has been reported in LPS-155301. Please ask support for a patch in order to fix it and run the migration database process again.
  • The display problem is solved by LPS-156283. Please ask support for a patch in order to fix it.
¿Fue útil este artículo?
Usuarios a los que les pareció útil: 0 de 0