Hi Guys,
Im trying to add parameter to a snippet that allows me to set a value when calling the snippet.
This is the original snippet.
<?php
function createNewResource( &$fields ){
global $modx;
$values = array();
$values['pagetitle'] = $modx->db->escape($fields['title']);
$values['longtitle'] = '';
$values['description'] = '';
$values['alias'] = '';
$values['published'] = 1; //0 - if you want the document to be created unpublished
$values['parent'] = 0; //id of the container for the the new document
$values['introtext'] = '';
$values['content'] = $modx->db->escape($fields['content']);
$values['template'] = 4; //the template of your new document
$values['searchable'] = 1;
$values['cacheable'] = 1;
$values['createdby'] = 1; //this is not the web user ID. Change it to an existing manager id
$values['createdon '] = time();
$values['editedby'] = 1; //this is not the web user ID. Change it to an existing manager id
$values['editedon '] = time();
//you can find more document properties by browsing the modx_site_content table
//insert the new document. In case you need the id of the new document use the $newId variable
$newId = $modx->db->insert( $values, $modx->getFullTableName('site_content') );
//clear the cache. in case you use Ditto to display the new document
clearCache();
return true;
}
function clearCache() {
include_once "manager/processors/cache_sync.class.processor.php";
$sync = new synccache();
$sync->setCachepath("assets/cache/");
$sync->setReport(false);
$sync->emptyCache();
}
?>
My edited version is
<?php
$params = array (
'conStart' => isset($conStart)? $conStart:'25',
);
function createNewResource( &$fields ){
global $modx;
$values = array();
$values['pagetitle'] = $modx->db->escape($fields['title']);
$values['longtitle'] = $modx->db->escape($fields['email']);
$values['description'] = '';
$values['alias'] = $modx->db->escape($fields['title']);
$values['published'] = 0; //0 - if you want the document to be created unpublished
$values['parent'] = $conStart; //id of the container for the the new document
$values['introtext'] = '';
$values['content'] = $modx->db->escape($fields['content']);
$values['template'] = 4; //the template of your new document
$values['searchable'] = 1;
$values['cacheable'] = 1;
$values['createdby'] = 1; //this is not the web user ID. Change it to an existing manager id
$values['createdon '] = time();
$values['editedby'] = 1; //this is not the web user ID. Change it to an existing manager id
$values['editedon '] = time();
//you can find more document properties by browsing the modx_site_content table
//insert the new document. In case you need the id of the new document use the $newId variable
$newId = $modx->db->insert( $values, $modx->getFullTableName('site_content') );
//clear the cache. in case you use Ditto to display the new document
clearCache();
return true;
}
function clearCache() {
include_once "manager/processors/cache_sync.class.processor.php";
$sync = new synccache();
$sync->setCachepath("assets/cache/");
$sync->setReport(false);
$sync->emptyCache();
}
?>
?>
The bits I have added are
$params = array (
'conStart' => isset($conStart)? $conStart:'25',
);
and
$values['parent'] = $conStart; //id of the container for the the new document
And when I call the snippet I use
[!createNewResource? &conStart=`60` !]
the conStart variable will just let me select the container I want the content to post to when I call the snippet.
Should be a simple solution im just new to coding snippets.
Any assistance appreciated