Create Page ProgrammaticallyCreate Page Programmaticallyhttps://liferay.dev/en/c/message_boards/find_thread?p_l_id=119785333&threadId=145917102024-03-29T11:48:47Z2024-03-29T11:48:47ZRE: Create Page ProgrammaticallyOlaf Kockhttps://liferay.dev/en/c/message_boards/find_message?p_l_id=119785333&messageId=1200714682020-10-09T07:53:20Z2020-10-09T07:53:20Z<div class="quote-title">Sanat D:</div><blockquote><br />i can create widget page by using above code. but can anyone tell me how can I create a content page by programmatically? should i have change any parameter type of the page and if yes then which type should I can use to create content page? Please reply.<br /></blockquote>On top of Mohammed's hint: <a href="https://github.com/olafk/layout-info-web">This portlet</a> might help with figuring out several settings.Olaf Kock2020-10-09T07:53:20ZRE: Create Page ProgrammaticallyMohammed Yasinhttps://liferay.dev/en/c/message_boards/find_message?p_l_id=119785333&messageId=1200652662020-10-08T13:32:35Z2020-10-08T13:32:35ZHi,<br />You can use LayoutConstants.TYPE_CONTENT type for creating content page.Mohammed Yasin2020-10-08T13:32:35ZRE: Create Page ProgrammaticallySanat Dhttps://liferay.dev/en/c/message_boards/find_message?p_l_id=119785333&messageId=1200625832020-10-08T08:56:47Z2020-10-08T08:56:47Zi can create widget page by using above code. but can anyone tell me how can I create a content page by programmatically? should i have change any parameter type of the page and if yes then which type should I can use to create content page? Please reply.<br />Thanks in advance.Sanat D2020-10-08T08:56:47ZRE: Create Page ProgrammaticallyEnrique Valdes Lacasahttps://liferay.dev/en/c/message_boards/find_message?p_l_id=119785333&messageId=620106442015-10-28T19:02:36Z2015-10-28T19:02:36Z<html><head></head><body>Using Liferay Layouts APIs, here is the code that works for me in 6.2:<br><br><pre><code>ServiceContext serviceContext = new ServiceContext();
Layout myPage = LayoutLocalServiceUtil.addLayout(userId, groupId, false,
0, "My Page", "Products", "My sample page",
LayoutConstants.TYPE_PORTLET, false, "/myPage", serviceContext);
</code></pre><br><br>userId: user adding the page<br>groupId: the id of the site<br>false: specifies it as a public page<br> LayoutConstants.TYPE_PORTLET: the type of page (in this case, a portlet page)<br>/myPage: the friendly URL selected for that page<br>serviceContext: allows us to specify more attributes for the page<br><br>Let's say you want to apply a page template for the page you create. Well, the serviceContext allows you to specify the page template (or layout prototype) in an attribute, according to the LayoutLocalServiceUtil.addLayout() documentation, where the method is well described. That would be done like this:<br><br>Note how you will need the page template Uuid for that, which is a lengthy String to identify page templates<br><pre><code>LayoutPrototype pageTemplate = LayoutPrototypeLocalServiceUtil.getLayoutPrototype(layoutPrototypeId);
String templateUuid = pageTemplate.getUuid();
ServiceContext serviceContext = new ServiceContext();
serviceContext.setAttribute("layoutPrototypeUuid", templateUuid);
serviceContext.setAttribute("layoutPrototypeLinkedEnabled", true);
Layout myPage = LayoutLocalServiceUtil.addLayout(userId, groupId, false,
0, "My Page", "Products", "My sample page",
LayoutConstants.TYPE_PORTLET, false, "/myPage", serviceContext);
</code></pre></body></html>Enrique Valdes Lacasa2015-10-28T19:02:36ZRE: Create Page ProgrammaticallyVitaliy Koshelenkohttps://liferay.dev/en/c/message_boards/find_message?p_l_id=119785333&messageId=146027462012-06-27T16:39:27Z2012-06-27T16:39:27Z<html><head></head><body>Something like this:<br><br><pre><code> long userId = themeDisplay.getUserId();
long groupId = themeDisplay.getScopeGroupId();
ServiceContext serviceContext = new ServiceContext();
LayoutLocalServiceUtil.addLayout(
userId,
groupId,
false, //not private
0, //has no parent layout
"some_name",
"some_title",
"some_description",
"portlet", //type
false, //not hidden
"/new-page", //friendly URL
serviceContext
);</code></pre><br><br>..but I have not tested it yet.</body></html>Vitaliy Koshelenko2012-06-27T16:39:27ZCreate Page Programmatically