Skip to content

feat: add Twig template engine driver as sibling to Latte#88

Merged
markshust merged 1 commit into
developfrom
feature/view-twig
May 27, 2026
Merged

feat: add Twig template engine driver as sibling to Latte#88
markshust merged 1 commit into
developfrom
feature/view-twig

Conversation

@markshust
Copy link
Copy Markdown
Collaborator

Summary

  • Adds new marko/view-twig driver package — full Twig 3 engine with strict_variables (loud errors), HTML autoescape, and module-namespaced template resolution
  • Refactors marko/view to be genuinely driver-neutral — removed Latte-biased extension and strict_types defaults; dropped ViewConfig::strictTypes() accessor
  • Refactors marko/view-latte to ship its own config and new LatteViewConfig class (architectural symmetry with TwigViewConfig)

Architectural changes

Interface/driver split tightened. Before this PR, marko/view shipped .latte as its default view.extension and a Latte-specific strict_types flag — biasing the interface package toward one driver. Now each driver ships its own config/view.php with its own defaults; marko/view only owns the truly shared keys (cache_directory, auto_refresh).

Mutual exclusion at install time. Both drivers declare "conflict": {"other-driver": "*"} in composer.json. Installing both fails loudly at composer install rather than at runtime via BindingConflictException.

Driver-specific config accessors live with their drivers. New TwigViewConfig (in view-twig) and LatteViewConfig (in view-latte) host their respective driver-only settings. No driver-specific accessors pollute the shared ViewConfig.

No silent fallbacks. Every value TwigViewConfig and LatteViewConfig expose goes through ConfigRepositoryInterface — missing keys throw ConfigNotFoundException. All defaults live in config files, never in code.

Twig defaults (config/view.php)

  • extension: '.twig'
  • strict_variables: true — undefined variables throw, matching Marko's loud-errors principle
  • autoescape: 'html' — safe default for web apps
  • debug: false
  • charset: 'UTF-8'

Users override any of these in their app-level config/view.php.

Cross-cutting updates

  • NoDriverException now lists both marko/view-latte and marko/view-twig with composer require commands
  • Skeleton lists both drivers in its suggest block (Twig first for broader ecosystem familiarity); skeleton stays engine-agnostic with no hard view-driver dep
  • Docs site registers twig as a Shiki language for syntax highlighting (built-in, no custom grammar needed)
  • New docs page at docs/src/content/docs/packages/view-twig.md mirrors the existing view-latte.md structure
  • marko/view and marko/view-latte docs updated to reflect the driver-neutral interface package and the new LatteViewConfig class

Out of scope (follow-up plan)

  • marko/admin-panel ships only .latte templates — users installing view-twig instead of view-latte would hit template-not-found errors. The next plan extracts admin-panel templates into engine-specific sibling packages (marko/admin-panel-latte, marko/admin-panel-twig) and adds a CrossEngineTemplateParityTest in marko/view's test suite to mechanically enforce parity for all core engines.

Test plan

  • All marko/view tests pass (43 tests)
  • All marko/view-latte tests pass (28 tests — refactored LatteEngineFactory mocks updated)
  • All marko/view-twig tests pass (46 tests covering config, engine factory, module loader, view, module bindings, package structure)
  • All marko/skeleton tests pass (16 tests including new suggest-block assertions)
  • Docs site builds with no warnings about unknown twig language
  • Composer validates view-twig and refactored view-latte composer.json files
  • Standards enforced across all changed PHP files (strict_types, readonly classes, typed constants, @throws tags, expectation chaining)

🤖 Generated with Claude Code

- New marko/view-twig package with TwigView, TwigEngineFactory,
  ModuleLoader (Twig\Loader\LoaderInterface), and TwigViewConfig
- Refactor marko/view: remove Latte-biased extension/.strict_types
  defaults from shared config; drop ViewConfig::strictTypes() accessor
- Refactor marko/view-latte: introduce LatteViewConfig for Latte-only
  settings; add config/view.php shipping extension/.latte + strict_types
- Composer conflict declaration enforces one-driver-at-a-time at install
- NoDriverException now lists both marko/view-latte and marko/view-twig
- Skeleton composer.json suggests both drivers (Twig listed first)
- Docs site: register Twig as Shiki language for syntax highlighting

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@github-actions github-actions Bot added the enhancement New feature or request label May 27, 2026
@markshust markshust merged commit ebbfb40 into develop May 27, 2026
1 check passed
@markshust markshust deleted the feature/view-twig branch May 27, 2026 12:42
markshust added a commit that referenced this pull request May 27, 2026
…mark ready

Closes the gap left by deleting the conflict-blocks pilot task in the
previous commit. Tasks 005-025 each decrement by one (005 -> 004,
006 -> 005, ..., 025 -> 024). All cross-references updated:
- File names
- Task headers
- Depends-on fields
- _plan.md task table
- Prose references

Also updates two stale references to view-twig in Discovery Notes that
predated PR #88 / #92 (both drivers are now in monorepo, view rollout
is no longer a single-driver case).

Status: planning -> ready (plan-orchestrate expects this).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant