Hello, quick question:
I’m modifying the <img into <amp-img in the content area.
To do that I created a plugin: OnWebPagePrerender
Until here I got what I need but the last step I need is to save that $output back into the "content"
can anyone help me with that part, please?
~ unless there is a better way to do it!
I think Bob is right and you have to change the value of $modx->resource->_output like in these examples.
$modx->resource->_output already contains the markup for the whole page at this point and the tags have been processed. You can’t just read the value of the content field in this event and handle it separately.
I only need to replace the img tags for amp-img so the JS will read and process them.
In my mind a plugin OnWebPagePrerender is the way to go, will you do it that way?
It should be possible to do that. Just read the value of $modx->resource->_output and change that, instead of querying the object ($modx->getObject('modResource', array('id'=>$docID));).
If the replace should only take place in the content and you can’t isolate this part of the page in $modx->resource->_output, then maybe take a look at the event OnLoadWebDocument instead.
just make sure to add an unset to free memory after running the preg_replace, depending on the PHP version you are running on, could bump into memory leak issues, here’s a link where the issue its explained, I don’t know if this kind of memory leaks are alredy managed inside MODX but with this things its better safre than sorry.