feat(templates): add theme template loader via framework TemplateLoader#709
Open
aryanjasala wants to merge 1 commit into
Open
feat(templates): add theme template loader via framework TemplateLoader#709aryanjasala wants to merge 1 commit into
aryanjasala wants to merge 1 commit into
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. |
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'; |
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.