Tribune

Home » Liferay Portal » English » 3. Development

Vista Combinata Vista Piatta Vista ad Albero
Discussioni [ Precedente | Successivo ]
toggle
Ron J
Creating sites & setting layout templates programmatically
16 gennaio 2013 15.46
Risposta

Ron J

Punteggio: Junior Member

Messaggi: 45

Data di Iscrizione: 18 novembre 2012

Messaggi recenti

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
20 gennaio 2013 10.39
Risposta

Olaf Kock

LIFERAY STAFF

Punteggio: Liferay Legend

Messaggi: 3425

Data di Iscrizione: 23 settembre 2008

Messaggi recenti

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.