Skip to content

Commit

Permalink
🎨 Improve template hierarchy implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
Log1x committed Mar 30, 2024
1 parent 3b0df77 commit 83c5de2
Showing 1 changed file with 22 additions and 3 deletions.
25 changes: 22 additions & 3 deletions src/Roots/Acorn/Sage/Concerns/FiltersTemplates.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,28 @@ trait FiltersTemplates
*/
public function filterTemplateHierarchy($files)
{
return wp_is_block_theme() && current_theme_supports('block-templates')
? [...$files, ...$this->sageFinder->locate($files)]
: [...$this->sageFinder->locate($files), ...$files];
$templates = $this->sageFinder->locate($files);

if (
! function_exists('wp_is_block_theme') ||
! wp_is_block_theme() ||
! current_theme_supports('block-templates')
) {
return [...$templates, ...$files];
}

$paths = [];

if ($template = get_page_template_slug()) {
$paths = array_filter(
$templates,
fn ($file) => str_contains($file, $template)
);

$templates = array_diff($templates, $paths);
}

return [...$paths, ...$files, ...$templates];
}

/**
Expand Down

0 comments on commit 83c5de2

Please sign in to comment.