I’m not sure, did you want to import a number of pages or did you want to auto create some pages for testing? If only for testing you can use this little snippet:
<?php
//Snippet [[createResources]] by Uncle68
$createInFolder = 0; //Set to 0 to create main folders in root, or set an existing folders id
$parents = 4; // Number of parents to create or 0 to just create children
$children = 25; // Number of children to create
$template = 0; // Chose template for new docs
$published = 1; // Published or not
$output ='';
if ($parents) {
$x=1;$p=0;
$output .= '<p><strong>Creating ' . $parents . ' parents/folders.</strong></p><p>';
while ($p < $parents) {
$foldertitle = 'Folder ' . $x;
$content = 'Content ' . $x;
$par = $modx->newObject('modResource');
$par->set('pagetitle', $foldertitle);
$par->set('content', $content);
$par->set('published', $published);
$par->set('isfolder', 1);
$par->set('template', 2);
if ($modx->getObject('modResource',$createInFolder)) {
$par->set('parent', $createInFolder);
}
$par->save();
$newParents[] = $par->get('id');
$output .= 'Created parent/folder: ' . $par->get('pagetitle') . '<br />' ;
$p++;
$x++;
}
$output .= '</p>';
}
$x=1;$c=0;
$output .= '<p><strong>Creating ' . $children. ' children.</strong></p><p>'; ;
while ($c < $children) {
$childtitle = 'Child ' . $x;
$content = 'Content ' . $x;
$child = $modx->newObject('modResource');
$child->set('pagetitle', $childtitle);
$child->set('content', $content);
$child->set('published', $published);
if (!$newParents) { $prn = $createInFolder;
} else {
shuffle($newParents);
$prn = $newParents[0];
}
$child->set('parent', $prn);
$child->set('template', 2);
$child->save();
$newChildren[] = $child->get('id'); //Use if you want to create children to children
$output .= 'Created child: ' . $child->get('pagetitle') . ' with parent ' . $prn . '<br />' ;
$c++;
$x++;
}
$output .= '</p>';
return $output;With some modifications it could be used for importing from an array or textfile too I guess...
Create a snippet called "createResources" and call if from a page in front end.