woocommerce/plugins/woocommerce-blocks/assets/js/blocks/classic-template
Albert Juhé Lluveras 0205513556
Fix Classic Template block registration on WP 6.6 (#48730)
* Fix Classic Template block registration on WP 6.6

* Update Compatibility Layer docs

* Add changelog file

* Remove unused function

* Simplify logic
2024-06-26 12:20:22 +02:00
..
test fix unit test (https://github.com/woocommerce/woocommerce-blocks/pull/10409) 2023-07-31 12:26:20 +00:00
README.md Document template parts used by the Classic Template block (#48183) 2024-06-12 09:36:55 +02: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 Fix Classic Template block registration on WP 6.6 (#48730) 2024-06-26 12:20:22 +02:00
order-confirmation.tsx Update @woo.com email addresses to @woocommerce.com (#46387) 2024-04-19 21:11:01 +00: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 Increase product excerpt default length in Single Product template and block (#47651) 2024-05-31 08:19:06 +02: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.