Skip to content

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

Open
aryanjasala wants to merge 1 commit into
theme-elementary-v2from
refactor/templateloader-class
Open

feat(templates): add theme template loader via framework TemplateLoader#709
aryanjasala wants to merge 1 commit 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
Comment on lines +27 to +32
final class Templates extends TemplateLoader implements Shareable {

/**
* Hook prefix for this loader's filters and actions.
*/
private const HOOK_PREFIX = 'elementary';
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.

2 participants