This question has been answered by minauen. See the first response.
<?php
/* You need to set these from the data sent in the Ajax call */
// $tvId =
// $resourceId =
// $value =
/** @var $tvr modTemplateVarResource */
$fields = array(
'tmplvarid' => $tvId,
'contentid' => $resourceId,
);
$tvr = $modx->getObject('modTemplateVarResource', $fields);
if (! $tvr) {
$tvr = $modx->newObject('modTemplateVarResource');
$tvr->set('tmplvarid', $tvId);
$tvr->set('contentid', $resourceId);
}
$tvr->set('value', $value);
$tvr->save();Hi there,
For my first attempt at writting a custom template variable I need to use my own html markup and js for the manager front-end. Now I'm stuck with how to save the contents from my custom template variable to the modx_site_tmplvar_contentvalues table.
Unfortunately I can't find examples anywhere. Can anybody help me out?
Quote from: minauen at Jan 31, 2014, 09:39 AMHi there,
For my first attempt at writting a custom template variable I need to use my own html markup and js for the manager front-end. Now I'm stuck with how to save the contents from my custom template variable to the modx_site_tmplvar_contentvalues table.
Unfortunately I can't find examples anywhere. Can anybody help me out?
what exactly should this TV do?
something like this is allready possible with MIGX.
See this tutorial:
http://rtfm.modx.com/extras/revo/migx/migx.tutorials/migx.use-resource-specific-mediasource-and-multifile-uploader
This is loading a multifile-uploader, with drag/drop capability in a window with an iframe.
With a second button you can load the uploaded images into the MIGX-grid and you can sort them by drag/drop, activate/deactivate them, give them titles and descriptions.
Not unless a custom DB table is involved. See this for info on instantiating MODX http://bobsguides.com/blog.html/2013/07/13/using-modx-outside-of-modx/
You probably wouldn't need the user and resource parts of the code since you're just creating and saving a modTemplateVarResource object.
You will probably want to create a namespace so MODX will know where to find the processor and you'll need to put the processor in the right place.
You don't have to, but you might consider using the new class-based processors. They're pretty slick and I think your case is very simple. https://www.markhamstra.com/xpdo/2012/getting-started-with-class-based-processors-2.2/