I'm modifying the Editable plugin, so if the content file that it tries to open doesn't exist, it will create it instead of giving an error. I do it like this (this code is inside Editable.php component)
I made this function for creating the new content file:
private function createContent($file, $content = NULL) {
$object = Content::inTheme($this->page->controller->getTheme());
if (empty($content)) $content = pathinfo($file, PATHINFO_FILENAME);
$objectData = [
'fileName' => $file,
'markup' => $content
];
$object->fill($objectData);
$object->save();
$this->fireEvent('object.save', [$object, 'content']);
return $content;
}
And then I check if the file exists, and if not, I call the function like this:
if ((Content::loadCached($this->page->controller->getTheme(), $this->file)) === null) {
if (!$this->isEditor)
return '';
$this->createContent($this->file);
}
But then if I try to render my just created file:
$content = $this->renderContent($this->file);
I get this Exception:
An exception has been thrown during the rendering of a template ("The content file 'projects/share.htm' is not found.").
The file is created ok, if I reload the page it works. The exception only happens when I try to open the file just after creating it. What am I missing here?
(I got the code for creating new cms files from the Pages plugin)
Last updated