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

Site Editing: Plugin conditional templates #29076

Open
Sandstromer opened this issue Feb 17, 2021 · 4 comments
Open

Site Editing: Plugin conditional templates #29076

Sandstromer opened this issue Feb 17, 2021 · 4 comments
Labels
[Feature] Blocks Overall functionality of blocks [Feature] Templates API Related to API powering block template functionality in the Site Editor [Type] Enhancement A suggestion for improvement.

Comments

@Sandstromer
Copy link

What problem does this address?

Should a theme author wish to include a template that includes blocks(s) from another plugin, the template is available to edit/use without the dependent plugin being active.

Examples could be a product template designed to work with WooCommerce blocks, or a header template containing the WC product search.

There could be confusion should a user select the header template for use on a site where WooCommerce is not in use.

What is your proposed solution?

Have some way of a theme defining when a particular template/template part is available for use in the editor.

Could this be included in theme.json?

e.g.

{
  "pluginTemplates": [
    {
      "slug": "shop-header",
      "plugin": "woocommerce"
    },
    {
      "slug": "shop-sidebar",
      "plugin": "woocommerce"
    }
  ]
}

Run a check to see if the plugin in the woocommerce directory is active. If so, make the shop-header template available in the editor.

@talldan talldan added [Feature] Blocks Overall functionality of blocks [Feature] Full Site Editing labels Feb 18, 2021
@talldan
Copy link
Contributor

talldan commented Feb 18, 2021

@Sandstromer What happens right now? Do the blocks show as missing?

@Sandstromer
Copy link
Author

What happens right now? Do the blocks show as missing?

It very much depends on the block.

For example, some blocks will display - on the frontend - the html parts of the block but not the dynamic content.
While in the editor the same block may display a warning message such as Your site doesn’t include support for the "woocommerce/featured-category" block. You can leave this block intact, convert its content to a Custom HTML block, or remove it entirely.

With block patterns we can conditionally make them available because we use php.

I'm not sure whether we need conditional templates, or whether we can make do with block patterns?

Would love to hear some more thoughts on this.

@markhowellsmead
Copy link

Is this the correct ticket in which to mention conditional block display? For example, I need to be able to switch between a query loop and a "no posts found" message in e.g. block-templates/index.html. Is this not possible, or have I just not found the documentation yet? Without this, we're blocked from using the FSE features for all of our sites.

@webmandesign
Copy link
Contributor

I'd like to point out that this should be applicable not only for templates but also template parts. (As described in #51987)

In my opinion, the most flexible solution would be to provide a conditionCallback attribute for templates and template parts defined in theme.json. Such as:

"templateParts": [
	{
		"title": "Product archive content",
		"name": "woocommerce-archive-product",
		"conditionCallback": "is_woocommerce_active"
	}
],

"templates": [
	{
		"title": "Product archive",
		"name": "archive-product",
		"conditionCallback": "is_woocommerce_active"
	}
]

The conditionCallback value could be a PHP function name to call when checking whether the template or template part should be visible/accessible to a user.

I'm aware there is no "templates" key in theme.json, but maybe it would be beneficial to introduce such key so we can control templates this way.
The "customTemplates" key does not really help here as those templates should not be recognized as custom templates by WordPress either. They should not be available to choose from on page edit screen (as can be seen in #51987):

wc-templates-custom

@jordesign jordesign added the [Type] Enhancement A suggestion for improvement. label Sep 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Blocks Overall functionality of blocks [Feature] Templates API Related to API powering block template functionality in the Site Editor [Type] Enhancement A suggestion for improvement.
Projects
None yet
Development

No branches or pull requests

6 participants