bobbingwide / thisis

ThisIs ... experimental Full Site Editing theme
GNU General Public License v3.0
1 stars 0 forks source link

Add debug divs to templates with appropriate CSS #11

Open bobbingwide opened 3 years ago

bobbingwide commented 3 years ago

In Fizzie I found it useful to create debug div at the top of each template part. It's styled with CSS so that the template name is either visible in the admin bar or appears when you hover over it, when not logged in. I think this will be a useful thing to have in this theme as well.

Requirements

Proposed solution

bobbingwide commented 3 years ago

I've started to develop a new plugin SB Debug block ( https://github.com/bobbingwide/sb-debug-block ) to replace the hardcoded divs with a dynamic Server Side Rendered block.

In order to get this to work for templates I've had to change Gutenberg.

To get it to work for template-parts, I can override the template-part rendering logic and implement the solution there. It requires two do_action calls, one before and the other after the actual rendering.

/**
  * Tell sb-debug-block we're rendering a template part.
  */
do_action( 'rendering_template_part', $attributes, $seen_ids );

After

/**
 * Tell sb-debug-block we've finished rendering a template part.
 */
do_action( 'rendering_template_part', null, $seen_ids );
bobbingwide commented 3 years ago

A similar solution can be used in template rendering. I can replace the original prototyped solution with:

 function gutenberg_override_query_template( $template, $type, array $templates = array() ) {
        global $_wp_current_template_content;
+       global $_wp_current_template;
        $current_template = gutenberg_resolve_template( $type, $templates );
+       bw_trace2( $current_template, "Current template");
+       bw_backtrace();
+       // Set the current template's details.
+       $_wp_current_template = $current_template;

with

     $current_template = gutenberg_resolve_template( $type, $templates );
+   do_action( 'rendering_template', $current_template, $type, $templates );

Once that's been demonstrated to work I can then add the do_action( 'rendering_template_part' ) calls to Gutenberg's template part rendering function and eventually eliminate the need for my own logic in the override function.

bobbingwide commented 3 years ago

The do_action() calls will need doc blocks.

paaljoachim commented 3 years ago

Hey Herb

This PR might be associated: Added filters to get block templates functions. https://github.com/WordPress/gutenberg/pull/31806/

bobbingwide commented 3 years ago

Note: The rendering_template_part hook does not currently pass enough information to enable the debugger to determine the source of the template part. The rendering_template hook provides this in $current_template. It would be nice if there were a similar function to gutenberg_resolve_template for template parts.