resolve_block_template example

$show_on_front = get_option( 'show_on_front' );
    $front_page_id = get_option( 'page_on_front' );

    if ( 'page' === $show_on_front && $front_page_id ) {
        return array(
                'postType' => 'page',
                'postId'   => $front_page_id,
        );
    }

    $hierarchy = array( 'front-page', 'home', 'index' );
    $template  = resolve_block_template( 'home', $hierarchy, '' );

    if ( ! $template ) {
        return null;
    }

    return array(
            'postType' => 'wp_template',
            'postId'   => $template->id,
    );
}


    public function get_template_fallback( $request ) {
        $hierarchy = get_template_hierarchy( $request['slug']$request['is_custom']$request['template_prefix'] );

        do {
            $fallback_template = resolve_block_template( $request['slug']$hierarchy, '' );
            array_shift( $hierarchy );
        } while ( ! empty( $hierarchy ) && empty( $fallback_template->content ) );

        $response = $this->prepare_item_for_response( $fallback_template$request );

        return rest_ensure_response( $response );
    }

    /** * Checks if the user has permissions to make the request. * * @since 5.8.0 * * @param WP_REST_Request $request Full details about the request. * @return true|WP_Error True if the request has read access, WP_Error object otherwise. */
array( get_stylesheet_directory() . '/', get_template_directory() . '/' ),
            '',
            $template
        );
        $index                  = array_search( $relative_template_path$templates, true );

        // If the template hierarchy algorithm has successfully located a PHP template file,         // we will only consider block templates with higher or equal specificity.         $templates = array_slice( $templates, 0, $index + 1 );
    }

    $block_template = resolve_block_template( $type$templates$template );

    if ( $block_template ) {
        $_wp_current_template_id = $block_template->id;

        if ( empty( $block_template->content ) && is_user_logged_in() ) {
            $_wp_current_template_content =
            sprintf(
                /* translators: %s: Template title */
                __( 'Empty template: %s' ),
                $block_template->title
            );
        }
Home | Imprint | This part of the site doesn't use cookies.