-
Notifications
You must be signed in to change notification settings - Fork 117
Idea: Using block markup and block CSS classes outside the content #4
Comments
I don't think that's a great idea personally unless it's already an FSE theme. We were looking at ways to lazy-load block assets and doing this make such thing impossible. The framework needs to know where blocks are being used. That said, theme authors are probably already doing so and when we introduce lazy-loading, we'd have to figure out a way to "warn" them. |
Yes you are right that is a valid point that I did not consider. It also means that global styles will be less useful for non FSE themes. @aristath posted an idea where the theme would be able to choose how the CSS is loaded, with theme support and filters But for this theme both backwards compatibility and future proofing is important. |
It is possible to have both.... Then instead of loading template parts using function twentytwentyone_do_the_template_part_blocks( $template ) {
ob_start();
get_template_part( $template ); // So that translations and logic works
echo do_blocks( ob_get_clean() );
} The above method is a semi-FSE approach to building a theme and can take advantage of things we do in the block editor (like lazy-load assets on block-render) |
This interests me because one of my first ideas (months ago when it still felt like we had all the time in the world) was to create the FSE theme first and just add the needed PHP functions, since the styles would be the same. |
Making an FSE theme work without FSE actually existing is definitely possible. <?php
ob_start();
include get_theme_file_path( 'page.html' );
echo do_blocks( ob_get_clean() ); Or even more abstract, a function inside the |
While I think that's clever, I'm not sure it's something we should on a WP default theme where I think IMO simplicity matters. |
@aristath Do you have an example theme ready where the files are doubled? |
I just tried this with a test theme. So until the FSE blocks like We can still use this method for template-parts that only include blocks available in wp-core, but it wouldn't be worth the mess. |
I experimented recently with building an FSE theme that has block markup in the templates and ran into a number of issues. The first problem is that class names have changed in recent past and are likely to change again in future for a number of the blocks. Chasing a moving target of the classnames, markup and styles seems unfeasable. |
To be able to change colors of the header and footer area with global styles, only a group block CSS class or perhaps a column CSS class would be needed :) Those are not likely to change. That is the absolute simplest version, but with the json file there are many more possibilities. |
This idea is based on 3 things:
By using block markup for sections outside the content, the theme can take advantage of CSS that is already in WP core.
For example, a header and footer with two or 3 columns can be built using markup and CSS that matches a columns block.
It reduces the CSS that needs to be in the theme.
It helps prepare the theme for when global styles is available.
By using the same CSS classes used by different blocks, global styles can be used to style the entire site and not only the content. -Without extra options in the customizer.
And thirdly, it makes creating an FSE version easier since the PHP version would already use block markup.
It might not be possible to use block markup for everything but that's OK.
It does not limit us to using only block CSS classes.
It needs testing through different WP versions to assure backwards compatibility
I would be interested in hearing more pros and cons.
Partial footer, where the columns flex styles would be provided by the block library style.
`
The text was updated successfully, but these errors were encountered: