Skip to content

Instantly share code, notes, and snippets.

@evilj0e
Created July 27, 2014 09:22
Show Gist options
  • Save evilj0e/b4df34ca6dc24dc5324b to your computer and use it in GitHub Desktop.
Save evilj0e/b4df34ca6dc24dc5324b to your computer and use it in GitHub Desktop.
Snippet for MODx Revolution to generate documents with your data
<?php
/**
* AutoGenerator Snippet to generate documents with your data
*
* @version 0.1
* @author Anton Konev (devdigital.ru)
*
* @example [[AutoGenerator? &parentid=`0`]]
*
* @var parent of documents $parentid
* @var document's data $data
*
*/
/* checking data array*/
isset( $data ) ?
$data :
$data = array(
'<p>Text</p>',
'<p>Text</p>',
);
foreach ($data as $index => $value) {
$product = $modx->newObject( 'modResource' );
$product->fromArray(
array(
'pagetitle' => 5000+$index,
'alias' => 5000+$index,
'longtitle' => '',
'parent' => $parentid,
'published' => 1,
'hidemenu' => 0,
'isfolder' => 1,
'searchable' => 1,
'template' => 12,
'content' => $value
)
);
$product->save();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment