Forums

Home » Liferay Portal » English » 3. Development

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

Ron J

Rank: Junior Member

Posts: 44

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

 1
 2List<LayoutSetPrototype> lsps = LayoutSetPrototypeServiceUtil.search(themeDisplay.getCompanyId(), Boolean.TRUE, null);
 3
 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);
 7
 8for (LayoutSetPrototype curLSP: lsps)
 9{
10    if (HtmlUtil.escape(curLSP.getName()).equalsIgnoreCase(SITE_TEMPLATE_NAME))
11    {
12         LayoutTypePortlet ltp = (LayoutTypePortlet) layout.getLayoutType();
13      ltp.setLayoutTemplateId(userid, curLSP.getUuid());
14
15          LayoutLocalServiceUtil.updateLayout(ng.getGroupId(), layout.isPrivateLayout(),
16                                    layout.getLayoutId(), layout.getTypeSettings());
17    }
18}


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

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

Olaf Kock

LIFERAY STAFF

Rank: Liferay Legend

Posts: 1961

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.