开发者

Modx Evolution: How to access and modify a template variable (tv) before save?

开发者 https://www.devze.com 2023-03-31 20:50 出处:网络
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).

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号