Tutorial

Creating pages

As cplace.actions().createPage is a function with side effects this can only be used in scripts with the actions feature enabled, otherwise an error will be raised.

Table of contents
  1. Basic command
  2. Custom attributes
  3. Readers & Writers
  4. Advanced parameters

Basic command

The most basic usage of this method would just provide a name for the page, the space it shall be created in and its customType:

cplace.actions().createPage({
    name: 'Test page',
    space: 'space/iogef7klu9wjdj4l63ne4iyie',
    customType: 'my.custom.type'
});

Instead of providing the absolute Uid of the space you can also provide it by getting another page's space Uid like e.g. inside a change listener:

var page = changeEvent.getEntity();
cplace.actions().createPage({
    name: 'Test page',
    space: page.getSpaceId(),
    customType: 'my.custom.type'
});

This however would not set any attributes which - obviously - may not be the most desirable outcome.

Custom attributes

In most situations you probably want to assign values to some attributes and maybe even alter read and write access to the created page. You can set attributes of a page by using the customAttributes property in the page data object which defines attribute-name:value pairs. Lets advance the basic example a bit and define a customAttributes property:

customAttributes: {
    'cf.cplace.myBoolean': true,
    'cf.cplace.myString': "Can I have cake?",
    'cf.cplace.myReference': page,
    'cf.cplace.myNumbers': [23, 42, 1337]
}

Note that for references you can either provide the entity Uid as a string (like 'page/r1kinb5nep455jplve8rm20xj') or the whole entity like done above. Multiple values are assigned as arrays ([]) as also done in the example.

Readers & writers

It is also possible to set readers and writers of a created page through cplaceJS. To do that you can use the readers and writers properties of the provided page data object.

You can either set the properties to a specific value or set by providing the entity Uids of persons or groups or as objects like

readers: ['person/kpf1s9cjf8s2kaerf7g0pdrvk', 'group/bhhss96cpvvu9li110zb4zta9'],
writers: [personA, personB, editorsGroup]

or you alter the existing (default) configuration by adding persons and groups by providing a permissions object:

readers: {
    '+': ['person/kpf1s9cjf8s2kaerf7g0pdrvk']
},
writers: {
    '+': [personA, editorsGroup]
}

When creating a page the set is a hard operation meaning that this will override the default ('inherited') permissions, whereas the latter method will expand it by appending single users (or groups).

Advanced parameters

If you ever find yourself in the situation to select a layout for the created page up front do this by providing its internal name as the 'layout' property like

layout: 'layoutVariant_2'

This of course requires you to have at least one named layout to choose from and also that the internal name of that layout is known.

cplaceJS page creation also supports name generation of pages. To enable the name generation just provide the setGeneratedName option through a PageOptions object. When doing so you can also leave out the name property of the page:

cplace.actions().createPage({
    space: 'space/uid',
    customType: 'my.custom.type',
    customAttributes: {
        'cf.cplace.myBoolean': true,
        'cf.cplace.myString': "Can I have cake?",
        'cf.cplace.myReference': page,
        'cf.cplace.myNumbers': [23, 42, 1337]
    }
}, {
    setGeneratedName: true
});