Skip to content

Commit

Permalink
feat: add once() helper
Browse files Browse the repository at this point in the history
  • Loading branch information
BernhardBaumrock committed Jan 22, 2024
1 parent 0eeb184 commit 0938e98
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions RockFrontend.module.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ class RockFrontend extends WireData implements Module, ConfigurableModule
/** @var bool */
public $noAssets = false;

private $onceKeys = [];

/** @var string */
public $path;

Expand Down Expand Up @@ -1526,6 +1528,21 @@ public function minifyFile($file, $minFile = null): string
return $minFile->path;
}

/**
* Helper to display markup only once
*
* Usage with LATTE:
* <div n:if="$rockfrontend->once('demo')">
* Demo Content
* </div>
*/
public function once(string $key): bool
{
$found = in_array($key, $this->onceKeys);
$this->onceKeys[] = $key;
return !$found;
}

/**
* Get other's language url of current page
* For super-simple language switchers, see here:
Expand Down

0 comments on commit 0938e98

Please sign in to comment.