Automattic\WooCommerce\Blocks\Utils
BlockTemplateUtils::get_template_part()
Gets the template part by slug
Method of the class: BlockTemplateUtils{}
No Hooks.
Return
String
. The template part content.
Usage
$result = BlockTemplateUtils::get_template_part( $slug );
- $slug(string) (required)
- The template part slug.
BlockTemplateUtils::get_template_part() BlockTemplateUtils::get template part code WC 9.4.2
public static function get_template_part( $slug ) { $templates_from_db = self::get_block_templates_from_db( array( $slug ), 'wp_template_part' ); if ( count( $templates_from_db ) > 0 ) { $template_slug_to_load = $templates_from_db[0]->theme; } else { $theme_has_template = self::theme_has_template_part( $slug ); $template_slug_to_load = $theme_has_template ? get_stylesheet() : self::PLUGIN_SLUG; } $template_part = get_block_template( $template_slug_to_load . '//' . $slug, 'wp_template_part' ); if ( $template_part && ! empty( $template_part->content ) ) { return $template_part->content; } // phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents return file_get_contents( self::get_templates_directory( 'wp_template_part' ) . DIRECTORY_SEPARATOR . $slug . '.html' ); }