掲示板

Creating sites & setting layout templates programmatically

11年前 に Ron J によって更新されました。

Creating sites & setting layout templates programmatically

Junior Member 投稿: 45 参加年月日: 12/11/18 最新の投稿
I'm trying to create a new site programmatically in one of my portlets and I want to apply a layout template that I've created. I used one of the organization views as a reference to get the templates but I'm struggling to get the template assigned to my new sites. I'm new to liferay and still learning how it works but found


List<layoutsetprototype> lsps = LayoutSetPrototypeServiceUtil.search(themeDisplay.getCompanyId(), Boolean.TRUE, null);

Layout layout = LayoutLocalServiceUtil.addLayout(userid, ng.getGroupId(), false,
		        			0, SITE_LAYOUT_NAME, SITE_LAYOUT_TITLE, SITE_LAYOUT_DESC,
		        			LayoutConstants.TYPE_PORTLET, true, "/"+name, ctx);

for (LayoutSetPrototype curLSP: lsps)
{
    if (HtmlUtil.escape(curLSP.getName()).equalsIgnoreCase(SITE_TEMPLATE_NAME))
    {
         LayoutTypePortlet ltp = (LayoutTypePortlet) layout.getLayoutType();
	  ltp.setLayoutTemplateId(userid, curLSP.getUuid());

          LayoutLocalServiceUtil.updateLayout(ng.getGroupId(), layout.isPrivateLayout(),
	    	        				layout.getLayoutId(), layout.getTypeSettings());
    }
}
</layoutsetprototype>


I don't get any errors but my new sites are blank.. What am I missing?

Thanks
thumbnail
11年前 に Olaf Kock によって更新されました。

RE: Creating sites & setting layout templates programmatically

Liferay Legend 投稿: 6396 参加年月日: 08/09/23 最新の投稿
You might want to look at the sourcecode for sevencogs-hook, a plugin that came with Liferay CE until version 6.1.1 (GA1) (so you'll have to download an old version)

Unfortunately this plugin does not compile currently (some API changes), but it's well worth looking at it: The complexity is extremely low and it does exactly what you want to achieve - basically it uses the API to set up users, pages, articles, layouts etc.