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

Template Parts with no HTML tags #49071

Open
tomjn opened this issue Mar 14, 2023 · 12 comments
Open

Template Parts with no HTML tags #49071

tomjn opened this issue Mar 14, 2023 · 12 comments
Labels
[Block] Template Part Affects the Template Parts Block [Type] Enhancement A suggestion for improvement.

Comments

@tomjn
Copy link
Contributor

tomjn commented Mar 14, 2023

What problem does this address?

Sometimes it's useful to put commonly reused components in a template part, but template parts have a tag such as a <div> and this breaks markup/styling.

What is your proposed solution?

Tag-less template parts!

A "None" option in this dropdown would do the job:

Screenshot 2023-03-14 at 18 08 31

@Mamaduka Mamaduka added [Type] Enhancement A suggestion for improvement. [Block] Template Part Affects the Template Parts Block labels Mar 14, 2023
@Mamaduka
Copy link
Member

This is probably a duplicate of #36853.

@Thelmachido
Copy link

I will mark this as needing more information to proceed further as @talldan suggested.

@Thelmachido Thelmachido added the [Status] Needs More Info Follow-up required in order to be actionable. label Mar 15, 2023
@carolinan
Copy link
Contributor

I tried this recently in #48471

It is not possible to remove the element in the editors, so the front and editor would not match, this was considered a blocker.

It works on the front when the template part has no attributes. The template part has no styles like colors and padding on its own, but it has an option to add a class name, for example.

@aristath
Copy link
Member

aristath commented Mar 15, 2023

Sometimes it's useful to put commonly reused components in a template part, but template parts have a tag such as a <div> and this breaks markup/styling.

What you're describing there sounds more like a reusable block, not a template part... You can use reusable blocks already for things like that. They don't add a wrapping element, and their purpose is to do just that: group commonly reused components.
A template part is a semantically different thing, and needs a wrapper.

@tomjn
Copy link
Contributor Author

tomjn commented Mar 15, 2023

You can use reusable blocks already for things like that. They don't add a wrapping element, and their purpose is to do just that: group commonly reused components.

Our end product needs to be self-contained, we can't rely on creating reusable block posts in the database or bundling WXR imports with the theme to enable basic functionality.

It is not possible to remove the element in the editors, so the front and editor would not match, this was considered a blocker.

@carolinan do you have any details on what the blocker is? I'm seeing lots of references to the editor needing the wrapper, but nothing that says why or explains the problem

@Mamaduka
Copy link
Member

@tomjn, the block editor marks a group of elements as a block using a wrapper element. It's usually done by using the useBlockProps hook. It needs to be native DOM elements, so we cannot use <Fragment>.

@tomjn
Copy link
Contributor Author

tomjn commented Mar 15, 2023 via email

@Mamaduka
Copy link
Member

The reusable blocks also have a wrapper element in the editor, but there's no wrapper element when rendered on the front.

@tomjn
Copy link
Contributor Author

tomjn commented Mar 15, 2023

hmm could template parts do the same then? @carolinan's PR could be modified to do that easily, this part in particular https://github.com/WordPress/gutenberg/pull/48471/files#diff-28f36bb64fbbc8ce728db401b1e4cf30c9f44db7f5dcce1b7b0cc9ce60b1a209R169-R171

@aristath
Copy link
Member

Our end product needs to be self-contained, we can't rely on creating reusable block posts in the database or bundling WXR imports with the theme to enable basic functionality.

Hmmmm I see... maybe patterns could do the job then? They are self-contained in the theme and not saved in the database. They have the difference that they can be edited after getting imported, but perhaps for your scenario that's not a deal-breaker?
Apologies if the above is a bit irrelevant, just trying to figure out if it would be possible to reuse one of the already existing implementations in Gutenberg

@tomjn
Copy link
Contributor Author

tomjn commented Mar 15, 2023

The initial reason I raised this issue I've managed to sidestep using this pattern:

Screenshot 2023-03-15 at 13 15 49

Which had some issues that have mysteriously vanished with a hard refresh. Tagless block template parts would still be useful, I hadn't considered patterns though!

@github-actions
Copy link

Help us move this issue forward. This issue is being marked stale since it has no activity after 15 days of requesting more information. Please add info requested so we can help move the issue forward. Note: The triage policy is to close stale issues that need more info and no response after 2 weeks.

@github-actions github-actions bot added the [Status] Stale Gives the original author opportunity to update before closing. Can be reopened as needed. label Mar 31, 2023
@Mamaduka Mamaduka removed [Status] Needs More Info Follow-up required in order to be actionable. [Status] Stale Gives the original author opportunity to update before closing. Can be reopened as needed. labels Mar 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Block] Template Part Affects the Template Parts Block [Type] Enhancement A suggestion for improvement.
5 participants