Add hooks to indicate details of the template and template parts being rendered #32309
Labels
[Feature] Extensibility
The ability to extend blocks or the editing experience
[Feature] Templates API
Related to API powering block template functionality in the Site Editor
Needs Technical Feedback
Needs testing from a developer perspective.
[Type] Enhancement
A suggestion for improvement.
What problem does this address?
When developing a new theme it can be difficult to tell which template or template part is being rendered.
I added some debug information at the top of each of my templates to help identify the rendered template and template parts on the front end. eg
If I wanted to check whether or not the template was being loaded from the file I would change the text in the
div
by adding a time stamp.I subsequently attempted to develop a single block plugin ( https://github.com/bobbingwide/sb-debug-block ) that would semi-automate the information gathering. The block would not render anything when WP_DEBUG wasn't true.
In order to obtain the information I needed to display the debug information, I found I had to extend Gutenberg to add a couple of action hooks.
I propose that these action hooks become a standard part of Gutenberg/WordPress core.
These hooks will enable
What is your proposed solution?
Add two action hooks:
rendering_template
andrendering_template_part
./lib/full-site-editing/template-loader.php
rendering_template
will pass information about the selected template to the action hook./packages/block-library/src/template-part/index.php
which becomes /build/block-library/blocks/template-part.php
Add two
do_action
hooks forrendering_template_part
; one before the template part is rendered and the other after.On the first call the attributes to the template part are passed.
on the second call, the
$attributes
argument isnull
and the$seen_ids
array no longer contains the template part that was rendered.This allows action hook function to track the template part nesting and un-nesting.
For more information on my prototyped solution see bobbingwide/sb-debug-block#2
The text was updated successfully, but these errors were encountered: