Automattic\WooCommerce\Blocks\BlockTypes

MiniCartTitleItemsCounterBlock::render │ protected │ WC 1.0

Render the block.

Method of the class: MiniCartTitleItemsCounterBlock{}

No Hooks.

Returns

string. Rendered block type output.

Usage

// protected - for code of main (parent) or child class
$result = $this->render( $attributes, $content, $block );
$attributes(array) (required)
Block attributes.
$content(string) (required)
Block content.
$block(WP_Block) (required)
Block instance.

MiniCartTitleItemsCounterBlock::render() code WC 11.1.2

<?php
protected function render( $attributes, $content, $block ) {
	$cart            = $this->get_cart_instance();
	$cart_item_count = $cart ? $cart->get_cart_contents_count() : 0;

	// The following translation is a temporary workaround. It will be
	// reverted to the previous form `(%d items)` as soon as the
	// `@wordpress/i18n` package is available as a script module.

	// translators: %d number of items in the cart.
	$cart_item_text = __( '(items: %d)', 'woocommerce' );

	wp_interactivity_config(
		$this->get_full_block_name(),
		array(
			'itemsInCartTextTemplate' => $cart_item_text,
		)
	);

	wp_interactivity_state(
		$this->get_full_block_name(),
		array(
			'itemsInCartText' => sprintf( $cart_item_text, $cart_item_count ),
		)
	);

	$wrapper_attributes = get_block_wrapper_attributes(
		array(
			'data-wp-text'        => 'state.itemsInCartText',
			'data-wp-interactive' => 'woocommerce/mini-cart-title-items-counter-block',
		)
	);

	ob_start();
	?>
	<span <?php echo $wrapper_attributes; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>>
	</span>
	<?php
	return (string) ob_get_clean();
}