gutenberg icon indicating copy to clipboard operation
gutenberg copied to clipboard

Add an option to choose whether or not to render the Template Part wrapper

Open alexandrebuffet opened this issue 3 years ago • 1 comments

What problem does this address?

The block Template Part renders a wrapper element which is not always necessary.

For example, I have a Block Theme where I'd like to display a block that handles the display of the site header inside my Header template part. My block already handles everything (tag name, style and markup options...) and I'd like to get rid of the unnecessary <div> (or any other tag chosen) provided by the Template Part block.

What is your proposed solution?

I think it would be interesting to be able to choose not to render the wrapper and just display the content inside with an option in the admin and a condition in the block render.

In addition, the block_template_part() function (useful in Hybrid Theme) only displays the content inside a Template Part, without the wrapper div. I find this confuses the overall use of Template Parts.

alexandrebuffet avatar Aug 17 '23 10:08 alexandrebuffet

Just ran into this issue today as well. I needed to split two elements in my header template part so that I could have the lower nav be position: sticky, but because of the wrapper element, I had to create two fully separate template parts and modify every template instead.

This came up previously but, at the time, there was no solution because the editor needed the wrapper, and keeping things consistent between the editor and the frontend required the wrapper to exist in both places: https://github.com/WordPress/gutenberg/issues/36853.

Things have changed since then; blocks like synced patterns manage to offer this functionality just fine. It would be incredibly useful to have the flexibility to turn off the wrapper entirely for template parts.

eric-michel avatar May 16 '24 15:05 eric-michel