Not a big fan of modx, but sadly it's what we use in work.
I'm having trouble saving a modified template variable in modx evolution (1.0.5).
In my plugin, called with the OnBeforeDocFormSave event, I'm doing this to get and modify the tv:
//include global variables
global $content,$default_template,$tmplvars;
$f开发者_如何学编程oo = $tmplvars[$TV_ID][1] . "bar";
$tmplvars[$TV_ID][1] = $foo;
This doesn't appear to work. $foo is set but the tv isn't saved.
$TV_ID is the resource ID of the template variable I'm after.
There are numerous ways to get the TV with API calls, but how do I modify it before it's saved?
Any help appreciated.
Are you using Evo ot Revo?
I update a page counter in revo using a plugin on the OnWebPageComplete event like this:
<?php
$docID = $modx->resource->get('id'); //get the page id
$tvId = 9; //the tv id I want to change
$tv = $modx->getObject('modTemplateVar',$tvId); // get the obj.
$tv->setValue($docID, $tv->getValue($docID) + 1 ); // set it's new value
$tv->save(); // save the new value
-sean
This solution appears to work:
Called by the plugin on the OnBeforeDocFormSave event
//include global variables
global $content,$default_template,$tmplvars;
$foo = $tmplvars[$TV_ID][1] . "bar";
$tmplvars[$TV_ID][0] = $TV_ID; //added this line
$tmplvars[$TV_ID][1] = $foo;
where $TV_ID is the id of the Template Variable you are trying to modify.
精彩评论