public function onAfterWrite()
 {
     parent::onAfterWrite();
     $folderParts = explode('/', getcwd());
     array_pop($folderParts);
     $docRoot = implode('/', $folderParts) . '/';
     // create folder only if not set
     if (!$this->FolderID) {
         $rootFolder = Folder::find_or_make(self::$templatesRoot);
         $folder = Folder::find_or_make(self::$templatesRoot . '/' . $this->_toFilename($this->Title));
         $folder->ParentID = $rootFolder->ID;
         $folder->write();
         $this->FolderID = $folder->ID;
     } else {
         $folder = $this->Folder();
     }
     if ($this->TemplateFileID) {
         $tplFile = $this->TemplateFile();
     } else {
         $tplFile = new File();
         $tplFile->set_validation_enabled(false);
         $tplFile->Filename = $folder->Filename . $this->_templateFilename;
         $tplFile->ParentID = $folder->ID;
         $this->TemplateFileID = $tplFile->write();
     }
     if ($this->CSSFileID) {
         $cssFile = $this->CSSFile();
     } else {
         $cssFile = new File();
         $cssFile->set_validation_enabled(false);
         $cssFile->Filename = $folder->Filename . $this->_cssFilename;
         $cssFile->ParentID = $folder->ID;
         $this->CSSFileID = $cssFile->write();
     }
     if ($this->JSFileID) {
         $jsFile = $this->JSFile();
     } else {
         $jsFile = new File();
         $jsFile->set_validation_enabled(false);
         $jsFile->Filename = $folder->Filename . $this->_jsFilename;
         $jsFile->ParentID = $folder->ID;
         $this->JSFileID = $jsFile->write();
     }
     if (!$this->_written) {
         $this->_written = true;
         $this->write();
     }
     file_put_contents($docRoot . $tplFile->Filename, $this->TemplateContent);
     file_put_contents($docRoot . $cssFile->Filename, $this->CSSContent);
     file_put_contents($docRoot . $jsFile->Filename, $this->JSContent);
 }