acorn icon indicating copy to clipboard operation
acorn copied to clipboard

Template hierarchy filter: Preserve existing paths

Open strarsis opened this issue 4 years ago • 16 comments

@retlehs: Instead of solely returning the blade template path locate result, append it to the array of existing files passed to the template hierarchy filter handler, allowing Gutenberg Full Site Editing (FSE) to find and use block templates/template parts in the (Sage 10) theme.

This fix lets the Gutenberg Full Site Editing/FSE templates load in Gutenberg, while still allowing classic (blade) templates to be used (as for WooCommerce that currently doesn't fully use Gutenberg yet).

Useful resources

  • Workaround that short-circuits the filter instead (as a fix in a Sage 10 theme): roots/acorn#228

  • Discussion about the reasons on why Gutenberg Full Site Editing/FSE can't find block templates/template parts without the fix: https://discourse.roots.io/t/full-site-editing-fse-frontend-doesnt-load-template/21574/4?u=strarsis

  • Related issue in the Sage 10 repository (that uses this acorn library in its PHP runtime): roots/acorn#228

PSA

Double-check whether remove_theme_support('block-templates') is absent from your theme setup, as otherwise FSE will not work.

strarsis avatar Nov 20 '21 10:11 strarsis

@strarsis thanks for the PR! i'm seeing some really odd behavior when trying to test FSE

could you share a repo/branch with me that has sage 10 with your FSE changes applied to it?

retlehs avatar Dec 07 '21 00:12 retlehs

@retlehs: I see, yes I can prepare something that uses this patch and also has FSE features so this can be tested.

strarsis avatar Dec 12 '21 15:12 strarsis

@retlehs: Alright, this repository includes this patch, enables Gutenberg Full Site Editing/FSE and adds FSE block templates and block template parts as demonstration: https://github.com/strarsis/sage10-fse (edit)

strarsis avatar Dec 12 '21 16:12 strarsis

@strarsis did you forget the link, and if so is this the one https://github.com/strarsis/sage10-fse?

stefanfisk avatar Dec 15 '21 11:12 stefanfisk

@stefanfisk: Yes, indeed! I forgot to link the repo: https://github.com/strarsis/sage10-fse

(WordPress site themes directory)

git clone https://github.com/strarsis/sage10-fse
cd sage10-fse
composer install
# to prevent the `Bootloader::findPath() must be of the type string` issue
npm install
npm run build

Activate theme.

strarsis avatar Dec 15 '21 11:12 strarsis

@stefanfisk: The repo was updated and works now with latest WordPress, Gutenberg plugin and Sage 10 theme. Discussion: https://discourse.roots.io/t/full-site-editing-fse-frontend-doesnt-load-template/21574/16?u=strarsis

strarsis avatar Oct 22 '22 15:10 strarsis

Any news on this? FSE support with Acorn/Sage would be really great.

ouun avatar Nov 25 '22 14:11 ouun

I'm running it fine by overriding the SageServiceProvider and not binding the template filters, so that all templates are in FSE. Running it with WooCommerce

oxyc avatar Nov 25 '22 14:11 oxyc

@oxyc: Would this be a better approach than modifying the acorn template filter as in this PR? @ouun: If you have the time, could you try out the linked Sage 10 FSE theme example and see whether it works? It is Sage 10 with the patched acorn library.

strarsis avatar Nov 25 '22 14:11 strarsis

To me it makes sense to not the bind the filters in the first place. I have no php templates in my theme since I opted in to FSE. I can still use blade in blocks

oxyc avatar Dec 08 '22 12:12 oxyc

@oxyc: Speaking of unbinding or short-circuiting filters, I had to force the Blade-PHP template filter to skip when a PHP-file already exists. Without this additional adjustment, some part of the HTML page markup would be rendered twice (<header>), which wouldn't be noticeable visually, but cause unexpected behavior (Popup maker).

So ideally the Sage template filter can use Blade-PHP templates, fall back to block templates and finally usual PHP files. The adjustments in this PR would allow for this behavior.

strarsis avatar Dec 08 '22 18:12 strarsis

Side note/FWIW: fellow devs who still need PHP 7.x support, the patch-2 branch has this fix also applied, but on the highest possible acorn version that still supported PHP 7.3: https://github.com/strarsis/acorn/tree/fse-php7

strarsis avatar Mar 16 '23 12:03 strarsis

Does this need more work to get into acorn core?

broskees avatar May 01 '23 13:05 broskees

There is a modification to one of the PR changes by @r-chrzan which appears to improve the loading behavior (Blade-PHP templates override FSE template files): https://github.com/strarsis/sage10-fse/issues/1#issuecomment-1480357953

strarsis avatar May 01 '23 18:05 strarsis

Hey guys, how does this PR looks like? You think it can be merged into Acorn core any time soon? Thanks!

palicko avatar Dec 14 '23 08:12 palicko

Hey guys, how does this PR looks like? You think it can be merged into Acorn core any time soon? Thanks!

By the way, there is also another PR now that may handle hybrid theme situations better: https://github.com/roots/acorn/pull/314

Independent from the particular acorn fix, you may find this Sage 10 FSE example theme base interesting: https://github.com/strarsis/sage10-fse

strarsis avatar Dec 14 '23 09:12 strarsis

Awesome! 👍

strarsis avatar Mar 18 '24 18:03 strarsis