Create a new page

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

  1. the template of the new page
  2. a link element (list, container, anchor) where to connect the new page
  3. 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.

String logonGuid="0904ABF0E43443D2881FE7481339650E";
String sessionKey="490EC675042F4C5A8A6DF1ED63ADD7A6";
String projectGuid="268F46EF5EB74A75824856D3DA1C6597";

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.

Note:

Advertisements
Post a comment or leave a trackback: Trackback URL.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: