Skip to content

Commit

Permalink
fix: prevent loading AutoPrepend on non-templatefile render() calls
Browse files Browse the repository at this point in the history
  • Loading branch information
BernhardBaumrock committed Jan 19, 2024
1 parent 594dd2b commit 0eeb184
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
7 changes: 7 additions & 0 deletions AutoPrepend.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@
* RockFrontend.
*/

// first we check if the currently rendered file matches the $page's templateFile
// this is to prevent issues when anything uses $files->render() before the
// page render is triggered (for example using setPageNameReplacements in
// Site::migrate())
$templateFile = $this->wire('page')->template->filename;
if ($templateFile !== $rockfrontend->autoPrependFile) return;

// If page is not set or not a page we exit early.
// This happens if anything calls wireRenderFile() on init or such.
// If the page is not available we also don't want to merge any defined variables.
Expand Down
5 changes: 4 additions & 1 deletion RockFrontend.module.php
Original file line number Diff line number Diff line change
Expand Up @@ -561,7 +561,10 @@ public function assetPath($path): string
*/
public function autoPrepend($event)
{
$event->object->setPrependFilename($this->path . "AutoPrepend.php");
/** @var Templatefile $tpl */
$tpl = $event->object;
$this->autoPrependFile = (string)$tpl;
$tpl->setPrependFilename($this->path . "AutoPrepend.php");
}

/**
Expand Down

0 comments on commit 0eeb184

Please sign in to comment.