Skip to content

Instantly share code, notes, and snippets.

@sonicpunk
Created January 11, 2018 07:15
Show Gist options
  • Save sonicpunk/0d02ed86fc5870f43cfe6bfb49a03385 to your computer and use it in GitHub Desktop.
Save sonicpunk/0d02ed86fc5870f43cfe6bfb49a03385 to your computer and use it in GitHub Desktop.
migrateContent to JSON for importing to another site
<?php
$parents = explode(',',$modx->getOption('parents',$scriptProperties,'11,10,12,13,14'));
$parents = array_unique($parents);
$output = array();
foreach ($parents as $parent) {
$childrenOutput = array();
$children = $modx->getCollection('modResource', array('parent'=>$parent));
foreach ($children as $child) {
$tvOutput = array();
$tvs = $child->getTemplateVars();
foreach ($tvs as $tv){
$tvOutput[] = $tv->toArray();
}
$childrenOutput[$child->get('id')] = array(
'pagetitle'=>$child->get('pagetitle'),
'longtitle'=>$child->get('longtitle'),
'content'=>$child->get('content'),
'description'=>$child->get('description'),
'tvs' => $tvOutput
);
}
$output[$parent] = $childrenOutput;
}
return json_encode($output);
@sonicpunk
Copy link
Author

Throw this in a snippet and add the snippet to a resource and call up the resource in the frontend to generate your json

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment