get_block_template example

return apply_filters( 'get_block_file_template', $block_template$id$template_type );
}

/** * Prints a block template part. * * @since 5.9.0 * * @param string $part The block template part to print. Use "header" or "footer". */
function block_template_part( $part ) {
    $template_part = get_block_template( get_stylesheet() . '//' . $part, 'wp_template_part' );
    if ( ! $template_part || empty( $template_part->content ) ) {
        return;
    }
    echo do_blocks( $template_part->content );
}

/** * Prints the header block template part. * * @since 5.9.0 */

    public function get_item( $request ) {
        if ( isset( $request['source'] ) && 'theme' === $request['source'] ) {
            $template = get_block_file_template( $request['id']$this->post_type );
        } else {
            $template = get_block_template( $request['id']$this->post_type );
        }

        if ( ! $template ) {
            return new WP_Error( 'rest_template_not_found', __( 'No templates exist with that id.' ), array( 'status' => 404 ) );
        }

        return $this->prepare_item_for_response( $template$request );
    }

    /** * Checks if a given request has access to write a single template. * * @since 5.8.0 * * @param WP_REST_Request $request Full details about the request. * @return true|WP_Error True if the request has write access for the item, WP_Error object otherwise. */
Home | Imprint | This part of the site doesn't use cookies.