Skip to content
This repository has been archived by the owner on Nov 6, 2022. It is now read-only.

Block theme folder structure #372

Merged
merged 2 commits into from
Jul 23, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions php/blocks/class-loader.php
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,7 @@ public function enqueue_block_styles( $name, $type = 'block' ) {
$locations = array_merge(
$locations,
array(
"blocks/{$name}/{$type}.css",
"blocks/css/{$type}-{$name}.css",
"blocks/{$type}-{$name}.css",
)
Expand Down Expand Up @@ -378,10 +379,10 @@ public function block_template( $name, $type = 'block' ) {
}

$template_file = "blocks/{$type}-{$name}.php";
$generic_file = "blocks/{$type}.php";
$templates = [
$generic_file,
"blocks/{$name}/{$type}.php",
$template_file,
"blocks/{$type}.php",
];

$located = block_lab_locate_template( $templates );
Expand Down
7 changes: 7 additions & 0 deletions tests/php/blocks/test-class-loader.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,15 +93,22 @@ public function test_enqueue_block_styles() {

if ( ! file_exists( $stylesheet_path . '/blocks/' ) ) {
mkdir( $stylesheet_path . '/blocks/' );
}
if ( ! file_exists( $stylesheet_path . '/blocks/css/' ) ) {
mkdir( $stylesheet_path . '/blocks/css/' );
}
if ( ! file_exists( $stylesheet_path . "/blocks/{$block_name}/" ) ) {
mkdir( $stylesheet_path . "/blocks/{$block_name}/" );
}

// In order of reverse priority.
$files = array(
"{$stylesheet_path}/blocks/block-{$block_name}.css",
"{$stylesheet_path}/blocks/css/block-{$block_name}.css",
"{$stylesheet_path}/blocks/{$block_name}/block.css",
"{$stylesheet_path}/blocks/preview-{$block_name}.css",
"{$stylesheet_path}/blocks/css/preview-{$block_name}.css",
"{$stylesheet_path}/blocks/{$block_name}/preview.css",
);

// Remove previous template files so that we can correctly check load order.
Expand Down