Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add debug divs to templates with appropriate CSS #11

Open
bobbingwide opened this issue Apr 28, 2021 · 5 comments
Open

Add debug divs to templates with appropriate CSS #11

bobbingwide opened this issue Apr 28, 2021 · 5 comments
Assignees

Comments

@bobbingwide
Copy link
Owner

bobbingwide commented Apr 28, 2021

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

  • Ability to easily determine which template is being displayed.

Proposed solution

  • Same as for Fizzie
@bobbingwide
Copy link
Owner Author

bobbingwide commented May 18, 2021

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
Copy link
Owner Author

bobbingwide commented May 19, 2021

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
Copy link
Owner Author

The do_action() calls will need doc blocks.

@paaljoachim
Copy link

Hey Herb

This PR might be associated:
Added filters to get block templates functions.
WordPress/gutenberg#31806

@bobbingwide
Copy link
Owner Author

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.

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

No branches or pull requests

2 participants