GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Fall back to the shipped templates instead of failing by onigoetz · Pull Request #601 · dauxio/daux.io

Conversation

@onigoetz

@onigoetz onigoetz commented Sep 10, 2026

Copy link
Copy Markdown
Contributor

Fixes #329

The problem

Running daux generate from a repository that happens to contain an unrelated templates/ folder fails:

Generating ...
- index.html                                                          [ FAIL ]
In Template.php line 155:
  The template "theme::home" could not be found at "templates/home.php".

Two defects combine to cause this.

The templates config value was a bare relative string. ConfigBuilder set 'templates' => 'templates' and never normalized it, unlike docs_directory and themes_directory which both go through findLocation(). Since local_base is the Daux install root, the value was clearly meant to point at Daux's own templates/ folder. Because it stayed relative, is_dir($base) resolved it against the current working directory and picked up whatever folder of that name sat in the user's repository.

Plates only offers a single-level fallback. addFolder('theme', $theme, true) falls back to the engine's default directory and nowhere else. The shipped themes have no templates/ subfolder, so Template::getEngine() set $theme = $base, and every theme::* lookup landed in the hijacked folder with no escape hatch.

Worth noting that the failure above is the lucky outcome. If the unrelated folder happened to contain a file named home.php or content.php, Daux silently rendered it instead of the real template.

The fix

Templates are now looked up through an ordered chain, and the first match wins:

theme::home ->
  1. <themes_path>/<theme>/templates/home.php
  2. <config.templates>/home.php     (only when explicitly configured)
  3. <daux>/templates/home.php       (always exists)

This preserves today's precedence, where the theme outranks the base directory, and adds the third level that was missing.

libs/Format/HTML/TemplateResolver.php (new)

Implements League\Plates\Template\ResolveTemplatePath, the extension point Plates 3.6 provides for exactly this. It walks the directories in order and returns the first one holding the template. When none does, it throws TemplateNotFound listing every path it tried rather than only the last one, which makes a genuine typo far easier to diagnose:

The template "theme::nonexistent" could not be found in any of these locations:
/path/to/mythemes/mytheme/templates/nonexistent.php, templates/nonexistent.php,
/path/to/daux.io/templates/nonexistent.php

Plates ships its own ThemeResolveTemplatePath with a similar hierarchy, but it builds paths from the full template name, so it is incompatible with the theme:: prefix that every template and every existing custom theme already uses.

libs/Format/HTML/Template.php

getEngine() builds the chain, dropping entries that do not exist and de-duplicating so the default case does not list the shipped directory twice. The Plates engine directory and the theme folder registration are kept because Name::setFolder() throws when the folder is unknown and Folder::setPath() throws on a missing directory, but both now point at the shipped templates and the real lookup is entirely the resolver's job. The verbose log line prints the whole chain instead of a base directory and a theme folder.

A side benefit: unprefixed names such as $this->layout('layout/00_layout') now resolve through the same chain rather than only hitting the engine's default directory.

libs/ConfigBuilder.php

The default templates value is now absolute, anchored on local_base. An unrelated folder in the working directory is never picked up.

This deliberately does not go through findLocation(): that helper checks the current directory before local_base, which would reintroduce the very hijack being removed. An explicitly configured relative value keeps behaving as it does today, because the resolver still tests every candidate with is_dir().

docs/10_For_Developers/Creating_a_Theme.md

Documents the lookup order. The page already promised that you can override "one template at a time"; this is what makes that reliable.

Tests

  • tests/Format/HTML/TemplateResolverTest.php covers the resolver directly: first match wins, a directory missing the file is skipped, nested names resolve, and an unresolvable name reports every searched path.
  • tests/Format/HTML/TemplateOverrideTest.php is the end-to-end regression test. It points templates at a directory holding only content.php, then asserts the landing page still renders from the shipped home.php while the content page uses the override. Confirmed to fail with the old getEngine(), reproducing the exact error from the issue, before passing with the fix.

The existing suite is unaffected. It runs with the working directory at the repository root, where templates/ is the shipped directory, and TranslateTest sets both candidate directories to values that are not directories, so its chain collapses to the shipped templates as before.

Compatibility

No configuration in the repository sets the templates key, and the documentation only ever described overriding templates inside a theme, so the working-directory pickup was an accident rather than a feature. Anyone who does set templates explicitly keeps their current behaviour, and now gets fallback on top of it.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@onigoetz
Fall back to the shipped templates instead of failing
1ddb41a
@onigoetz
onigoetz merged commit c0a0f56 into master Sep 10, 2026
7 checks passed

Uh oh!

There was an error while loading. Please reload this page.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

The template "theme::home" could not be found at "templates/home.php"

Uh oh!

There was an error while loading. Please reload this page.

1 participant

@onigoetz
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.