Skip to content

Commit

Permalink
fix: error when less field not used
Browse files Browse the repository at this point in the history
  • Loading branch information
BernhardBaumrock committed Oct 6, 2023
1 parent 7eb4ecc commit 495c186
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions RockFrontend.module.php
Original file line number Diff line number Diff line change
Expand Up @@ -601,14 +601,21 @@ private function createCSS()

public function createCustomLess(HookEvent $event): void
{
// if the less field does not exist we exit early
$lessField = $this->wire->fields->get(self::field_less);
if (!$lessField) return;

// if the less file already exists we have nothing to do
// the less file will be deleted on page save
$file = $this->lessFilePath();
if (is_file($file)) return;
$less = $this->wire->pages->get(1)->getFormatted(self::field_less);

// create only if directory templates/less exists
// make sure that the less directory exists
$dir = $this->wire->config->paths->templates . "less";
if ($less and !is_dir($dir)) $this->wire->files->mkdir($dir);
if (!is_dir($dir)) $this->wire->files->mkdir($dir);

// write less content to file
$this->wire->files->filePutContents($file, $less);
}

Expand Down

0 comments on commit 495c186

Please sign in to comment.