Automattic\WooCommerce\Blocks\BlockTypes
ClassicTemplate::render()
Render method for the Classic Template block. This method will determine which template to render.
Метод класса: ClassicTemplate{}
Хуков нет.
Возвращает
Строку
. | void Rendered block type output.
Использование
// protected - в коде основоного (родительского) или дочернего класса $result = $this->render( $attributes, $content, $block );
- $attributes(массив) (обязательный)
- Block attributes.
- $content(строка) (обязательный)
- Block content.
- $block(WP_Block) (обязательный)
- Block instance.
Код ClassicTemplate::render() ClassicTemplate::render WC 7.5.1
protected function render( $attributes, $content, $block ) { if ( ! isset( $attributes['template'] ) ) { return; } /** * We need to load the scripts here because when using block templates wp_head() gets run after the block * template. As a result we are trying to enqueue required scripts before we have even registered them. * * @see https://github.com/woocommerce/woocommerce-gutenberg-products-block/issues/5328#issuecomment-989013447 */ if ( class_exists( 'WC_Frontend_Scripts' ) ) { $frontend_scripts = new \WC_Frontend_Scripts(); $frontend_scripts::load_scripts(); } $archive_templates = array( 'archive-product', 'taxonomy-product_cat', 'taxonomy-product_tag', ProductAttributeTemplate::SLUG, ProductSearchResultsTemplate::SLUG ); if ( 'single-product' === $attributes['template'] ) { return $this->render_single_product(); } elseif ( in_array( $attributes['template'], $archive_templates, true ) ) { // Set this so that our product filters can detect if it's a PHP template. $this->asset_data_registry->add( 'is_rendering_php_template', true, true ); // Set this so filter blocks being used as widgets know when to render. $this->asset_data_registry->add( 'has_filterable_products', true, true ); $this->asset_data_registry->add( 'page_url', html_entity_decode( get_pagenum_link() ), '' ); return $this->render_archive_product(); } else { ob_start(); echo "You're using the ClassicTemplate block"; wp_reset_postdata(); return ob_get_clean(); } }