Question

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;

$foo = $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.

Was it helpful?

Solution 2

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.

OTHER TIPS

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top