Skip to content

Commit

Permalink
Templates: Integrate with demo content.
Browse files Browse the repository at this point in the history
  • Loading branch information
epiqueras committed Jul 8, 2019
1 parent 3d7df87 commit 214f929
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
6 changes: 6 additions & 0 deletions lib/templates.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@ function gutenberg_register_templates() {
$template = $template[0];
}

if ( isset( $_GET['gutenberg-demo'] ) ) {
ob_start();
include gutenberg_dir_path() . 'post-content.php';
$template->post_content = ob_get_clean();
}

$post_type_object = get_post_type_object( 'post' );
$post_type_object->template = $template;
}
Expand Down
5 changes: 4 additions & 1 deletion packages/blocks/src/api/templates.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,10 @@ export function synchronizeBlocksWithTemplate( blocks = [], template ) {
return blocks;
}

return map( template, ( { name, attributes, innerBlocks: innerBlocksTemplate }, index ) => {
return map( template, ( templateBlock, index ) => {
const [ name, attributes, innerBlocksTemplate ] = Array.isArray( templateBlock ) ?
templateBlock :
[ templateBlock.name, templateBlock.attributes, templateBlock.innerBlocksTemplate ];
const block = blocks[ index ];

if ( block && block.name === name ) {
Expand Down
3 changes: 3 additions & 0 deletions post-content.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
*/

?>
<!-- wp:post-title /-->
<!-- wp:post-content -->
<!-- wp:cover {"url":"https://cldup.com/Fz-ASbo2s3.jpg","className":"alignwide"} -->
<div class="wp-block-cover has-background-dim alignwide" style="background-image:url(https://cldup.com/Fz-ASbo2s3.jpg)"><div class="wp-block-cover__inner-container"><!-- wp:paragraph {"align":"center","placeholder":"Write title…","fontSize":"large"} -->
<p style="text-align:center" class="has-large-font-size"><?php _e( 'Of Mountains &amp; Printing Presses', 'gutenberg' ); ?></p>
Expand Down Expand Up @@ -184,3 +186,4 @@
<!-- wp:paragraph {"align":"center"} -->
<p style="text-align:center">👋</p>
<!-- /wp:paragraph -->
<!-- /wp:post-content -->

0 comments on commit 214f929

Please sign in to comment.