Hi guys,
I’m running a custom page revisions plugin on my modx install and I need to modify the template variable values that are shown when you edit a page.
I cant work out how to change them.. there doesnt seem to be a handy variable like $content for template variables (this is ondocformprerender). Does anyone have any ideas?
Cheers, Rich
As far as I know there is no specific API for managing (altering, adding, deleting) template variables. You have to use the MODx dbapi and
this info about how the TVs are stored in the MODx database tables to change them.
You might also find
Sottwell’s documentation useful, since it points to the MODx core code that handles template variables. You can copy how it is done from there.
I don’t know if there are any snippets available to help you achieve what you want.
-
☆ A M B ☆
- 24,524 Posts
You should be able to take a leaf from the ManagerManager book and use javascript (ManagerManager uses the jquery library) to change the value of the TV’s field after the form has been rendered, using the OnDocFormRender event. You could use the DOM to change the value of the TV’s form field to whatever you wanted. I would imagine a good javascript/DOM inspection utility like Firebug would be invaluable.
-
☆ A M B ☆
- 24,524 Posts
You can’t manipulate the values used in building the form, because these forms were all created well before events and plugins were thought of. The frames for the forms are built as standard PHP/HTML pages, with inline PHP getting the data as it is required by the various form fields. The OnDocFormPrerender event is triggered before the form output is started, and the OnDocFormRender event is triggered after the entire form has been displayed.
If it were redone properly, the document’s data would be collected into an array, then the OnDocFormPrerender event could be called with that array, and the plugin could modify the elements of the array. Afterward the form would be built using the array. A really good implementation would have the entire form built and stored in a variable, like the parser does the documentOutput, then the OnDocFormRender event could manipulate the whole form before it gets displayed.
Ahh. I see. Sorry, I misunderstood what you were asking for. Have you seen this
content history plugin? I *think* this tracks the history template variables too, so perhaps it already does what you want without requiring your custom plugin?
Thanks guys, my plugin is based on content_history, although heavily rewritten as its not quite flexible enough to do what my client wants.
I’m going to go the javascript route, its horrible and I feel like a chump for doing it but thems the breaks i guess.
Cheers