This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.

Maria Vilaró
Maria Vilaró

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

Ryan Donohue
Ryan Donohue

Did you ever figure this out?

Maria Vilaró
Maria Vilaró

No, never, I just lived with it. The files are created so I just hit F5 if I get the error. And now I changed the plugin so it uses the database (translate messages) instead of content files so I don't have this problem anymore. Mistery forever.

1-3 of 3

You cannot edit posts or make replies: the forum has moved to talk.octobercms.com.