Message Boards

Liferay 7.2 - Define a specific look and feel for a page programmatically

Fabio Carvalho, modified 4 Years ago.

Liferay 7.2 - Define a specific look and feel for a page programmatically

Junior Member Posts: 81 Join Date: 6/25/19 Recent Posts
Hi,

I have been creating my pages programmatically like this:
Layout layout = LayoutLocalServiceUtil.fetchLayoutByFriendlyURL(myGroupId, false, myPageUrl);
if (layout == null) layout = LayoutLocalServiceUtil.addLayout(
    myUserId, 
    myGroupId, 
    false, 
    LayoutConstants.DEFAULT_PARENT_LAYOUT_ID, 
    myPageName, 
    null, 
    null, 
    LayoutConstants.TYPE_PORTLET, 
    false, 
    myPageUrl, 
    new ServiceContext()
);

Now I am trying to set the theme like this:
LayoutLocalServiceUtil.updateLookAndFeel(
    layout.getGroupId(), 
    layout.getPrivateLayout(), 
    layout.getLayoutId(), 
    myThemeId, 
    layout.getColorSchemeId(), 
    layout.getCss()
);

The problem is that the page is created, but the theme is not updated. I am pretty sure, the problem is that when the page is created the "Look and Feel" is by default  Use the same look and feel of the Public Pages."and because of that my custom theme is not applied. How to I set my layout "Look and Feel" to be by default to "Define a specific look and feel for this page."?
Fabio Carvalho, modified 4 Years ago.

RE: Liferay 7.2 - Define a specific look and feel for a page programmatical

Junior Member Posts: 81 Join Date: 6/25/19 Recent Posts
I ended up with changing some parameters and is working now:
LayoutLocalServiceUtil.updateLookAndFeel(
    layout.getGroupId(), 
    layout.getPrivateLayout(), 
    layout.getLayoutId(), 
    myThemeId, 
    theme.getColorSchemeId(), 
    theme.getPathThemeCss()
);
thumbnail
Aravinth Kumar, modified 3 Years ago.

RE: Liferay 7.2 - Define a specific look and feel for a page programmatical

Regular Member Posts: 152 Join Date: 6/26/13 Recent Posts
I too faced this issue and able to resolve by passing colorschemeid.
ColorShemeId can be fetched from themelocalserviceutil for a particular theme. 
I just passed "01" as default value and there is no error.
layoutLocalService.updateLookAndFeel(groupId, privateLayout, layout.getLayoutId(), themeId,
                            "01", layoutCss);