Skip to content

Commit

Permalink
Rename as pageTemplates and support a nested config
Browse files Browse the repository at this point in the history
  • Loading branch information
youknowriad committed Dec 21, 2020
1 parent 4c19336 commit 434752c
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 30 deletions.
29 changes: 0 additions & 29 deletions lib/full-site-editing/custom-templates.php

This file was deleted.

35 changes: 35 additions & 0 deletions lib/full-site-editing/page-templates.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php
/**
* Support for page templates.
*
* @package gutenberg
*/

/**
* Load the page templates in Gutenberg.
*
* @param array $templates Theme page templates.
* @return array Modified templates.
*/
function gutenberg_load_fse_page_templates( $templates ) {
if ( ! gutenberg_is_fse_theme() ) {
return $templates;
}
$config_file = locate_template( 'experimental-theme.json' );
if ( ! file_exists( $config_file ) ) {
return $templates;
}
$data = json_decode(
file_get_contents( $config_file ),
true
);
$page_templates = array();
if ( isset( $data['pageTemplates'] ) ) {
foreach ( $data['pageTemplates'] as $key => $page_emplate ) {
$page_templates[ $key ] = $page_emplate['title'];
}
}

return $page_templates;
}
add_filter( 'theme_page_templates', 'gutenberg_load_fse_page_templates' );
2 changes: 1 addition & 1 deletion lib/load.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ function gutenberg_is_experiment_enabled( $name ) {
require __DIR__ . '/full-site-editing.php';
require __DIR__ . '/full-site-editing/default-template-types.php';
require __DIR__ . '/full-site-editing/templates-utils.php';
require __DIR__ . '/full-site-editing/custom-templates.php';
require __DIR__ . '/full-site-editing/page-templates.php';
require __DIR__ . '/templates-sync.php';
require __DIR__ . '/templates.php';
require __DIR__ . '/template-parts.php';
Expand Down

0 comments on commit 434752c

Please sign in to comment.