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.