Home » Liferay Portal » English » 3. Development

Combination View Flat View Tree View
Threads [ Previous | Next ]
Ron J
Creating sites & setting layout templates programmatically
January 16, 2013 3:46 PM

Ron J

Rank: Junior Member

Posts: 45

Join Date: November 18, 2012

Recent Posts

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

 2List<LayoutSetPrototype> lsps =, Boolean.TRUE, null);
 4Layout layout = LayoutLocalServiceUtil.addLayout(userid, ng.getGroupId(), false,
 5                            0, SITE_LAYOUT_NAME, SITE_LAYOUT_TITLE, SITE_LAYOUT_DESC,
 6                            LayoutConstants.TYPE_PORTLET, true, "/"+name, ctx);
 8for (LayoutSetPrototype curLSP: lsps)
10    if (HtmlUtil.escape(curLSP.getName()).equalsIgnoreCase(SITE_TEMPLATE_NAME))
11    {
12         LayoutTypePortlet ltp = (LayoutTypePortlet) layout.getLayoutType();
13      ltp.setLayoutTemplateId(userid, curLSP.getUuid());
15          LayoutLocalServiceUtil.updateLayout(ng.getGroupId(), layout.isPrivateLayout(),
16                                    layout.getLayoutId(), layout.getTypeSettings());
17    }

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

Olaf Kock
RE: Creating sites & setting layout templates programmatically
January 20, 2013 10:39 AM

Olaf Kock


Rank: Liferay Legend

Posts: 4060

Join Date: September 23, 2008

Recent Posts

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.