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

Conversation

lukecarbis
Copy link
Member

This PR adds support for structuring blocks inside directories like so:

  • /theme
    • /blocks
      • /block_one
        • preview.php
        • block.php
        • block.css
      • /block_two
        • preview.php
        • block.php
        • block.css

Note that it does not auto-enqueue javascript files, as suggested in the original issue (we should open a separate issue for that, if one doesn't already exist).

Block templates are expected to load in the following order:

  1. blocks/{name}/preview.php (if in the editor)
  2. blocks/preview-{name}.php (if in the editor)
  3. blocks/preview.php (if in the editor)
  4. blocks/{name}/block.php
  5. blocks/block-{name}.php
  6. blocks/block.php

Block styles are expected to load in the following order:

  1. blocks/{name}/preview.css (if in the editor)
  2. blocks/css/preview-{name}.css (if in the editor)
  3. blocks/preview-{name}.css (if in the editor)
  4. blocks/{name}/block.css
  5. blocks/css/block-{name}.css
  6. blocks/preview-{name}.css

Closes #301.

@lukecarbis
Copy link
Member Author

Here's my testing:

Theme folder structure:
Screen Shot 2019-07-23 at 8 41 19 am

In the editor:
Screen Shot 2019-07-23 at 8 40 53 am

On the frontend:
Screen Shot 2019-07-23 at 8 40 37 am

The correct template was loaded.

@kienstra
Copy link
Collaborator

kienstra commented Jul 23, 2019

Looks Good!

Hi @lukecarbis,
The code looks good, and this works for both the child theme and the parent theme.

Child Theme

child-theme

Parent Theme

parent-theme

Nice documentation here on the order of the template and stylesheet loading, like:

Block templates are expected to load in the following order:

@lukecarbis
Copy link
Member Author

@RobStino Think you could add those docs to the wiki?

@lukecarbis lukecarbis merged commit 314bf85 into develop Jul 23, 2019
@lukecarbis lukecarbis deleted the feature/301-block-theme-folder-structure branch July 23, 2019 03:39
lukecarbis added a commit to lukecarbis/block-lab that referenced this pull request Aug 18, 2019
…-theme-folder-structure

Block theme folder structure
@martinszeltins
Copy link

Hi, is this already in production? Because I'm still not able to put my blocks in folders... Version 1.3.5

@lukecarbis
Copy link
Member Author

lukecarbis commented Aug 27, 2019

@martinszeltins Yes! It's in production, and seems to be working well for me. What structure do you have?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Block Theme Folder Structure
3 participants