Skip to content

feat(templates): add theme template loader via framework TemplateLoader#709

Merged
aryanjasala merged 6 commits into
theme-elementary-v2from
refactor/templateloader-class
Jun 11, 2026
Merged

feat(templates): add theme template loader via framework TemplateLoader#709
aryanjasala merged 6 commits into
theme-elementary-v2from
refactor/templateloader-class

Conversation

@aryanjasala

Copy link
Copy Markdown
Member

What this does

Adds a Templates consumer to the theme, mirroring Core\Components — so the
theme can ship PHP template parts that a child theme overrides, resolved through
the framework TemplateLoader. The loader is self-aware: because the theme's own
parts already sit in the (parent) theme, the package layer collapses into the
theme override layer automatically (child theme > parent theme).

Changes

  • Add inc/Core/Templates.phpfinal class Templates extends TemplateLoader implements Shareable; context elementary; points at the theme's
    template-parts/ directory, overridable at child-theme/template-parts/.
  • inc/Main.php — register Templates in CLASSES.
  • inc/Helpers/Util.phpUtil::render_template() (echo) and
    Util::get_template() (string), backed by a shared template_loader() resolved
    via get_shared( Templates::class ) — mirroring Util::component.

How I verified

  • php -l clean on changed files.
  • Smoke test (framework symlinked): Templates extends TemplateLoader, is
    Shareable with a public no-arg constructor, registered in Main;
    Util::render_template / get_template resolve.

Reviewer notes

  • Stacks on the framework TemplateLoader PR. CI/runtime needs that merged to
    main; bump composer.lock to the new main tip once it is.
  • theme-elementary is an FSE theme, so this is wiring for any PHP template parts
    the theme (or its child) chooses to ship — no consumer-defined paths; resolution
    and override come from the framework loader.

Add a Core\Templates loader that extends the framework TemplateLoader and is
shared through the container, mirroring Core\Components. Expose render_template /
get_template helpers in Util. The theme can now ship PHP template parts a child
theme overrides at the same relative path.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR introduces a framework-backed template-part loader to the theme so PHP template parts can be resolved with child-theme overrides (child > parent) via rtCamp\WPFramework\TemplateLoader, plus helper methods to render or retrieve those template parts from PHP.

Changes:

  • Added a new Core\Templates loader (TemplateLoader + Shareable) targeting the theme’s template-parts/ directory.
  • Registered the new loader in Main::CLASSES so it is bootstrapped with the theme.
  • Added Util::render_template() and Util::get_template() helpers backed by the shared Templates instance.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
inc/Main.php Registers Core\Templates in Main::CLASSES so it loads with the theme bootstrap.
inc/Helpers/Util.php Adds render_template() / get_template() helper wrappers using the shared Templates loader.
inc/Core/Templates.php Introduces the new framework TemplateLoader consumer for theme template parts.

Comment thread inc/Core/Templates.php
Refresh composer.lock: rtcamp/wp-framework dev-main → 99a4e77, the main tip
now carrying the TemplateLoader class.
…h tests

Demonstrate the theme's TemplateLoader: an [elementary_author_bio] shortcode
renders the author-bio template part via Util::get_template(), overridable by a
child theme at template-parts/author-bio.php. Adds Templates wiring tests and a
shortcode render test.
WPCS flags top-level template-part variables as unprefixed globals (it cannot
see they are function-scoped via load_template()), so carry the theme prefix.
Also capitalise a test doc short description.
…o part

The variables are local to the load_template() include scope, not globals, so
disable the sniff for the file instead of carrying the theme prefix through
the markup.
@aryanjasala aryanjasala merged commit 1bab6af into theme-elementary-v2 Jun 11, 2026
7 checks passed
@aryanjasala aryanjasala deleted the refactor/templateloader-class branch June 11, 2026 11:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants