# _build_block_template_result_from_file()

URL: https://chugunov.pro/api-wordpress/functions/_build_block_template_result_from_file/
Проверено на WordPress 6.9, обновлено 06.08.2026.
Источник: независимый русскоязычный справочник chugunov.pro. Не является официальной документацией WordPress.

Тип: функция.
Появился в версии: 5.9.0.

## Сигнатура

```php
_build_block_template_result_from_file( array $template_file, string $template_type ): WP_Block_Template
```

## Описание

Создаёт унифицированный объект шаблона на основе файла темы.

## Параметры

- `$template_file` `array` — обязательный. Файл темы.
- `$template_type` `string` — обязательный. Тип шаблона. Либо 'wp_template', либо 'wp_template_part'.

## Возвращаемое значение

`WP_Block_Template`

## Исходный код

Файл: `wp-includes/block-template-utils.php:604`

```php
function _build_block_template_result_from_file( $template_file, $template_type ) {
	$default_template_types = get_default_block_template_types();
	$theme                  = get_stylesheet();

	$template                 = new WP_Block_Template();
	$template->id             = $theme . '//' . $template_file['slug'];
	$template->theme          = $theme;
	$template->content        = file_get_contents( $template_file['path'] );
	$template->slug           = $template_file['slug'];
	$template->source         = 'theme';
	$template->type           = $template_type;
	$template->title          = ! empty( $template_file['title'] ) ? $template_file['title'] : $template_file['slug'];
	$template->status         = 'publish';
	$template->has_theme_file = true;
	$template->is_custom      = true;
	$template->modified       = null;

	if ( 'wp_template' === $template_type ) {
		$registered_template = WP_Block_Templates_Registry::get_instance()->get_by_slug( $template_file['slug'] );
		if ( $registered_template ) {
			$template->plugin      = $registered_template->plugin;
			$template->title       = empty( $template->title ) || $template->title === $template->slug ? $registered_template->title : $template->title;
			$template->description = empty( $template->description ) ? $registered_template->description : $template->description;
		}
	}

	if ( 'wp_template' === $template_type && isset( $default_template_types[ $template_file['slug'] ] ) ) {
		$template->description = $default_template_types[ $template_file['slug'] ]['description'];
		$template->title       = $default_template_types[ $template_file['slug'] ]['title'];
		$template->is_custom   = false;
	}

	if ( 'wp_template' === $template_type && isset( $template_file['postTypes'] ) ) {
		$template->post_types = $template_file['postTypes'];
	}

	if ( 'wp_template_part' === $template_type && isset( $template_file['area'] ) ) {
		$template->area = $template_file['area'];
	}

	if ( 'wp_template_part' === $template->type ) {
		/*
		 * In order for hooked blocks to be inserted at positions first_child and last_child in a template part,
		 * we need to wrap its content a mock template part block and traverse it.
		 */
		$content           = get_comment_delimited_block_content(
			'core/template-part',
			array(),
			$template->content
		);
		$content           = apply_block_hooks_to_content(
			$content,
			$template,
			'insert_hooked_blocks_and_set_ignored_hooked_blocks_metadata'
		);
		$template->content = remove_serialized_parent_block( $content );
	} else {
		$template->content = apply_block_hooks_to_content(
			$template->content,
			$template,
			'insert_hooked_blocks_and_set_ignored_hooked_blocks_metadata'
		);
	}

	return $template;
}
```

## История изменений

- 6.3.0 — Added modified property to template objects.
- 5.9.0 — Introduced.

## Связанные

Использует: `WP_Block_Templates_Registry::get_instance`, [`apply_block_hooks_to_content`](https://chugunov.pro/api-wordpress/functions/apply_block_hooks_to_content/), [`remove_serialized_parent_block`](https://chugunov.pro/api-wordpress/functions/remove_serialized_parent_block/), [`get_default_block_template_types`](https://chugunov.pro/api-wordpress/functions/get_default_block_template_types/), [`get_comment_delimited_block_content`](https://chugunov.pro/api-wordpress/functions/get_comment_delimited_block_content/), [`get_stylesheet`](https://chugunov.pro/api-wordpress/functions/get_stylesheet/).
Используется в: [`get_block_file_template`](https://chugunov.pro/api-wordpress/functions/get_block_file_template/), [`get_block_templates`](https://chugunov.pro/api-wordpress/functions/get_block_templates/).

Оригинал в официальной документации: https://developer.wordpress.org/reference/functions/_build_block_template_result_from_file/
