woocommerce/plugins/woocommerce-blocks/assets/js/blocks/classic-template
Karol Manijak f5d9b3adaa
Hide AbstractProductGrid blocks from inserter (soft-deprecation) (#52209)
* Hide product grid blocks from inserter

* Expose collections in the inserter

* Arrange collections imports alphabetically and registering by usage

* Add new keywords to collections

* Update tests

* Update block references

* Add changelog

* Update docs manifest

* Fix typo in collection name in test

* MAke adjsutments and cleanup of collections keywords

* Add one more keyword

* Hide Related Products from inserter

* Replace legacy Related Products with collection when transforming classic template into block one

* Replace legacy Related Products with collection in blockified Single Product Template

* Update block references and doc manifest

* Update block references

* Update tests to reflect new collection names

* Bring back pnpm-lock to original state

* Update Related Products E2E tests

* Fix the last Related Products test

* Add default queryId to Related Products pattern

* Regenerate block references and docs manifest
2024-11-04 18:57:51 +01:00
..
test fix unit test (https://github.com/woocommerce/woocommerce-blocks/pull/10409) 2023-07-31 12:26:20 +00:00
README.md Update broken docs links (#51967) 2024-10-10 17:37:27 +01:00
archive-product.ts Replace Products (Beta) with Product Collection in product archive templates (#48112) 2024-06-12 15:45:09 +02:00
constants.ts Rename classic template blocks to avoid confusion (#44931) 2024-05-22 10:53:43 +02:00
editor.scss Add universal border radius for form elements and components (https://github.com/woocommerce/woocommerce-blocks/pull/11193) 2023-10-11 17:04:45 +01:00
index.tsx Update all blocks to V3 (#48720) 2024-08-20 10:14:11 +00:00
order-confirmation.tsx Delayed Account Creation Test Coverage (#51852) 2024-10-07 11:12:37 +01:00
product-search-results.ts Replace Products (Beta) with Product Collection in product archive templates (#48112) 2024-06-12 15:45:09 +02:00
single-product.ts Hide AbstractProductGrid blocks from inserter (soft-deprecation) (#52209) 2024-11-04 18:57:51 +01:00
style.scss Classic Template: set the default alignment to wide (https://github.com/woocommerce/woocommerce-blocks/pull/6356) 2022-05-04 18:02:42 +07:00
types.ts Rename classic template blocks to avoid confusion (#44931) 2024-05-22 10:53:43 +02:00
utils.ts [Blockifying Product Archive Templates]: Implement the blockified template conversion for the Classic Template Block. (https://github.com/woocommerce/woocommerce-blocks/pull/8248) 2023-02-27 15:34:18 +01:00

README.md

Classic Template Block

Table of Contents

The Classic Template block is a placeholder block for specific WooCommerce block templates which are rendered on the server side when a block theme is active. In the editor UI, it's presented with these names:

  • Product (Classic),
  • Product Attribute (Classic),
  • Product Taxonomy (Classic),
  • Product Tag (Classic),
  • Product Search Results (Classic),
  • Product Grid (Classic).

When the Classic Template block is clicked, a button appears to 'Transform into blocks'. Clicking it updates the template so it's composed of more granular blocks. That's what we commonly refer to as the 'blockified template'. The blockified template has several advantages over using the Classic Template block, like allowing users to hide some blocks from the template, changing their order or making more granular modifications.

Classic Template block in the Single Product template

Once the user has switched to the blockified template, a button will appear on the 'Template' sidebar allowing them to revert to the classic template, which adds back the Classic Template block.

Usage

This block does not have any customizable options available, so any style or customization updates will not be reflected on the placeholder.

Props

  • attributes
    • template: single-product | archive-product | taxonomy-product_cat | taxonomy-product_tag | taxonomy-product_attribute
    • align: wide | full
<!-- wp:woocommerce/legacy-template {"template":"single-product"} /-->

By assigning a template identifier to the attribute prop, the block will render that specific template on the front-end, and a placeholder for said template in the Site Editor.

It's worth noting that the placeholder in the Site Editor is merely an approximate representation of a template's front-end view.

Internals

The ClassicTemplate class is used to set up the Classic Template block server-side. This class takes care of rendering the correct template and is also responsible of enqueuing the front-end scripts necessary to enable dynamic functionality, such as the product gallery, add to cart, etc.

From the render() method we inspect the $attributes object for a template property which helps determine which core PHP templating code to execute (e.g. single-product) for the front-end views.

Extensibility

[!IMPORTANT] Before customizing or extending the Classic Template block, keep in mind that users can easily switch from the Classic Template block to the blockified version of the templates, so any customizations or extensibility changes should cover both paradigms.

PHP actions and filters

[!NOTE] Using PHP actions and filters to customize the look-and-feel of a store with a block theme is discouraged. We recommend using blocks, global styles, block hooks, and other block-based APIs. However, these filters can be useful to port some customizations from the blocks into the Classic Template block.

Internally, the ClassicTemplate class triggers several PHP hooks that are shared with classic themes. Those are:

Those hooks except woocommerce_show_page_title and woocommerce_shop_loop are also applied to the blockified version of templates thanks to the compatibility layer.

PHP template parts

[!NOTE] Using PHP template parts to customize the look-and-feel of a store with a block theme is discouraged. We recommend using blocks, global styles, block hooks, and other block-based APIs. However, these template parts can be useful to port some customizations from the blocks into the Classic Template block.

[!CAUTION] Unlike most PHP actions and filters mentioned above, the PHP template parts are not applied in the blockified version of the templates, so you should make sure to build a version of the same changes that works with blocks.

The ClassicTemplate class renders a couple of PHP template parts. Those are content-single-product template part in the Single Product version of the Classic Template block and the content-product template part when rendering the Product archive templates. Themes can override those template parts as they would normally do in classic themes, with content-single-product.php and content-product.php files. However, remember that these templates parts are not used in the blockified version of the templates, so any changes to them won't be applied to the granular blocks.


We're hiring! Come work with us!

🐞 Found a mistake, or have a suggestion? Leave feedback about this document here.