You know now how to access page information and dive from a top page to it’s children.
Now it’s time for the creation of new pages. What do we need? Accordingly to the MS philosophy we need
- the template of the new page
- a link element (list, container, anchor) where to connect the new page
- the headline.
I assume to create a new page on list fields_list on page F5030 of last example. We start with the usual lines of code.
Let get the template (the old name of what is the content class now). To get the template you need the folder name (=content_templates) and the name of the content class (=field_page) within that folder.
CmsClient client = new CmsClient(logonGuid);
Project project = client.getProject(sessionKey, projectGuid);
Template template = project.getTemplateByName(“content_templates”, “field_page”);
Now let’s access our sample page F5030 with page ID34009.
Page currentPg = project.getPageById("34009");
The creation of the new page on that list can be combined in the following line:
Page fieldPg = currentPg.createAndConnectPageAtList("fields_list", template, "new field page", true);
Rember, fields_list is the name of the content class list element and “new field page” is the headline of the new page.
But what’s the boolean at the end? The MS always creates new pages on a list at the top assuming it is a kind of news list. I didn’t want this and so I introduced a flag addAtBottom to be more flexible. If it is true, the new page will automatically sort at the end of the list. For further details, please check the JavaDoc.
The create method return the newly created page for further access.