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

FSE: Parse the template before <head> gets rendered #28319

Merged
merged 2 commits into from
Jan 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions lib/full-site-editing/template-loader.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,15 +154,14 @@ function gutenberg_render_title_tag() {
}

/**
* Renders the markup for the current template.
* Returns the markup for the current template.
*/
function gutenberg_render_the_template() {
function gutenberg_get_the_template_html() {
global $_wp_current_template_content;
global $wp_embed;

if ( ! $_wp_current_template_content ) {
echo '<h1>' . esc_html__( 'No matching template found', 'gutenberg' ) . '</h1>';
return;
return '<h1>' . esc_html__( 'No matching template found', 'gutenberg' ) . '</h1>';
}

$content = $wp_embed->run_shortcode( $_wp_current_template_content );
Expand All @@ -178,9 +177,14 @@ function gutenberg_render_the_template() {

// Wrap block template in .wp-site-blocks to allow for specific descendant styles
// (e.g. `.wp-site-blocks > *`).
echo '<div class="wp-site-blocks">';
echo $content; // phpcs:ignore WordPress.Security.EscapeOutput
echo '</div>';
return '<div class="wp-site-blocks">' . $content . '</div>';
}

/**
* Renders the markup for the current template.
*/
function gutenberg_render_the_template() {
echo gutenberg_get_the_template_html(); // phpcs:ignore WordPress.Security.EscapeOutput
}

/**
Expand Down
7 changes: 6 additions & 1 deletion lib/template-canvas.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@
* @package gutenberg
*/

/**
* Get the template HTML.
* This needs to run before <head> so that blocks can add scripts and styles in wp_head().
*/
$template_html = gutenberg_get_the_template_html();
?>
<!DOCTYPE html>
<html <?php language_attributes(); ?>>
Expand All @@ -16,7 +21,7 @@
<body <?php body_class(); ?>>
<?php wp_body_open(); ?>

<?php gutenberg_render_the_template(); ?>
<?php echo $template_html; // phpcs:ignore WordPress.Security.EscapeOutput ?>

<?php wp_footer(); ?>
</body>
Expand Down