Pimcore: Create pages via PHP-Code (incl. editables)

I was given the task to create pages of existing data. The challenge: the pages contain editables and these editables should be filled by pre-existing data.

All editables must be created prior to creating pages with the content.

A editable consists of one or multiple elements. each element must be created individually and later added to the areablock which than is saved as a page.

The areablock is created with a name and later on all content gets connected via the name. In this example it is named content for the ease of use.

This code creates a page construct, sets editables and saves it to the database


$editablesOnPage = [];

$pageInformationYouWantToCreate = [
    'page_title' => 'My first page',
    'folder_path' => '/',
    'seo_description' => 'Pages seo description',
    'seo_title' => 'Seo Title, if needed',


$positionOnPageFor = [
    'headline' => 1,
    'wysiwyg' => 2,

$foldertoCreateThePageUnder = 1; // Root folder id
$areaBlockName = 'content';

$importPage = new \Pimcore\Model\Document\Page();
    'seoTitle' => $pageInformationYouWantToCreate['seo_title'],

$blockArea = new \Pimcore\Model\Document\Editable\Areablock();

// Headline
if ($pageInformationYouWantToCreate['headline_title']) {
    $headline = new \Pimcore\Model\Document\Editable\Input();
    $headline->setName(sprintf('%s:%s.title', $areaBlockName, $positionOnPageFor['headline']));
    $editablesOnPage[] = $headline;

// Wysiwyg
if ($pageInformationYouWantToCreate['content_text']) {
    $wysiwygComponent = new \Pimcore\Model\Document\Editable\Wysiwyg();
    $wysiwygComponent->setName(sprintf('%s:%s.text', $areaBlockName, $positionOnPageFor['wysiwyg']));
    $editablesOnPage[] = $wysiwygComponent;

        'key'    => $pageInformationYouWantToCreate['headline'],
        'type'   => 'heading',
        'hidden' => false,
        'key'    => $pageInformationYouWantToCreate['wysiwyg'],
        'type'   => 'wysiwyg',
        'hidden' => false,

array_unshift($editablesOnPage, $blockArea);


Leave a Reply

Your email address will not be published. Required fields are marked *