Changing the document content in the controller to display in the view script

Hi,

I am trying to change the content of the page if the user takes a particular static path. I am able to pull the content in a controller function of the page that I would like to show, but I am unable to send it to the views script page and change the layout. This just ends up showing a blank screen or the error page that I have set for the site. I am using the following in my controller page function.

public function changePageAction() {
$document = \Pimcore\Model\Document::getByID($this->getParam(“id”));
$this->setDocument(\Pimcore\Model\Document::getByID($this->getParam(“id”)));
$this->enableLayout();
$this->view->layout()->setLayout($document->getTemplate());
}

I am trying to set the new content in the controller, but I am not seeing the pimcore function to do so, I am trying to replace the variables in my views script page such as the following to display the new content

$this->wysiwyg(“pageContent”)

Hopefully this makes sense and thank you for the help

1 Like

Have you tried setRawElement?

$document = \Pimcore\Model\Document::getById( $this->getParam( 'id' ) );
$document->setRawElement( 'pageContent', 'wysiwyg', '<h1>My Heading</h1>' );
$document->save();

I’ve not tested this but I think it should work.

Thank you for your help, this helped with changing the content but unfortunately the page just ends up on the error page instead of showing the changed content on the page.