feat(templates): add theme template loader via framework TemplateLoader#709
Merged
Merged
Conversation
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.
There was a problem hiding this comment.
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\Templatesloader (TemplateLoader+Shareable) targeting the theme’stemplate-parts/directory. - Registered the new loader in
Main::CLASSESso it is bootstrapped with the theme. - Added
Util::render_template()andUtil::get_template()helpers backed by the sharedTemplatesinstance.
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. |
Refresh composer.lock: rtcamp/wp-framework dev-main → 99a4e77, the main tip now carrying the TemplateLoader class.
pratik-londhe4
approved these changes
Jun 9, 2026
…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.
pratik-londhe4
approved these changes
Jun 11, 2026
…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.
pratik-londhe4
approved these changes
Jun 11, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
What this does
Adds a
Templatesconsumer to the theme, mirroringCore\Components— so thetheme can ship PHP template parts that a child theme overrides, resolved through
the framework
TemplateLoader. The loader is self-aware: because the theme's ownparts already sit in the (parent) theme, the package layer collapses into the
theme override layer automatically (child theme > parent theme).
Changes
inc/Core/Templates.php—final class Templates extends TemplateLoader implements Shareable; contextelementary; points at the theme'stemplate-parts/directory, overridable atchild-theme/template-parts/.inc/Main.php— registerTemplatesinCLASSES.inc/Helpers/Util.php—Util::render_template()(echo) andUtil::get_template()(string), backed by a sharedtemplate_loader()resolvedvia
get_shared( Templates::class )— mirroringUtil::component.How I verified
php -lclean on changed files.Templates extends TemplateLoader, isShareablewith a public no-arg constructor, registered inMain;Util::render_template/get_templateresolve.Reviewer notes
TemplateLoaderPR. CI/runtime needs that merged tomain; bumpcomposer.lockto the new main tip once it is.the theme (or its child) chooses to ship — no consumer-defined paths; resolution
and override come from the framework loader.