We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 12262
    • 40 Posts
    Hi folks,

    probably a simple question but I'm searching quite a while now (and yes, I'm pretty new to ModX Revo)...

    What I want to do is:
    A plugin that should change the content of the (rich) text editor whenever the resource is saved.

    How can I access (and change) the content of the resource in the OnBeforeDocFormSave or onDocFormSave event (which of the events would be better?)

    Is there a code fragment that could help me?

    Forgot to attach my code fragment (just for testing):
    $output =  $resource->get('content');
    
    $output = "<h1>just a test</h1>" . $output;
    
    $resource->set('content',$output);
    $resource->save();


    This basically changes the content but it does not show in the rich text editor...

    Thanks in advance

    Thomas [ed. note: hochmohr last edited this post 11 years, 5 months ago.]
    • OnBeforeDocFormSave provides a "resource" object, which contains all of the fields and their values. You can use $resource->content = 'my new content'; to change the content before it gets saved. Or $resource->set('content', 'my new content');

      The new content won't show up at first, you have to refresh the Manager page to see the changed content. [ed. note: sottwell last edited this post 11 years, 5 months ago.]
        Studying MODX in the desert - http://sottwell.com
        Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
        Join the Slack Community - http://modx.org
        • 12262
        • 40 Posts
        Thanks for the quick answer...

        ... I forgot to be more precise: Basically I can change the content (as shown now in my first post) but it does not show in the rich text editor (not unless I refresh the page).
        • Heh. Great minds think alike! I don't know the answer to that.
            Studying MODX in the desert - http://sottwell.com
            Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
            Join the Slack Community - http://modx.org
            • 6038
            • 228 Posts
            here's a link to a gist, that might help you create what you want - it's loose bootstrap code to update/change content on the fly when saving a resource:

            https://gist.github.com/2768300