Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue with extending blocks / creating new blocks in child theme #57

Open
JeStew opened this issue Nov 10, 2021 · 5 comments
Open

Issue with extending blocks / creating new blocks in child theme #57

JeStew opened this issue Nov 10, 2021 · 5 comments

Comments

@JeStew
Copy link

JeStew commented Nov 10, 2021

Hi there! Firstly, I love this plugin.

Some background - I'm using the Timber Starter Theme as the parent, with ACF, Timber, and Timber-ACF-WP-Blocks installed via Composer.

I don't know if this is an issue with the composer package, but it seems I'm unable to do the following things in regards to a Parent/Child theme setup:

A.) Cannot create another view/blocks directory in the child theme (the parent views/blocks directory becomes completely unavailable.)
B.) Cannot register new blocks if I install the package through composer again in the Child theme directory root (likely a symptom of point A.)
C.) Cannot extend block twig files in the child theme even when using the Timber loader to create a namespace for the blocks themselves (like a symptoms of point A. as well.)

I am able to create blocks putting the acf_register_block_type() function directly in to the Child functions.php and register new blocks. As long as I do not create a directory of views/blocks in the child, these new registers work fine.

Any help on this would be greatly appreciated!

@palmiak
Copy link
Owner

palmiak commented Nov 10, 2021

I think it may be related to the fact I'm using locate_template. Could I ask you for a zip with simplest example of your case?

@JeStew
Copy link
Author

JeStew commented Nov 10, 2021

Thanks for your swift response!

Due to the privacy of the code- I had to recreate this with the bare bones, but left some comments to help illustrate.

This only contains the parent and child themes, with the assumptions you have ACF Pro and Timber installed on your setup. Timber ACF WP Blocks is included via composer. Hopefully this works for you!

child-parent-demo.zip

@JeStew
Copy link
Author

JeStew commented Nov 12, 2021

Hi @palmiak, just wanted to follow up on this.

IWhen using the filter to create a custom directory to find the blocks, I was actually able to create new blocks in the child by passing an array (one element being a full path) in the Parent theme like so:

add_filter( 'timber/acf-gutenberg-blocks-templates', function () { return [ 'blocks', get_stylesheet_directory() . '/blocks' ]; // default is 'views/blocks'. } );

However, this still leaves all of the parent theme blocks broken and I'm unable to extend the blocks in to the child.

Im looking in to the locate_template route you mentioned, so if I have any ideas I'll let you know!

Hope this helps and thanks again,

@JeStew
Copy link
Author

JeStew commented Nov 12, 2021

Sorry to keep pinging, played around with the locate_template function and did find that that could be the culprit.

I'm not a PHP expert, but combining this filter that adds the directory paths

add_filter(
	'timber/acf-gutenberg-blocks-templates',
	function () {
		return [  get_template_directory() . '/blocks', get_stylesheet_directory() . '/blocks' ]; // default is 'views/blocks'.
	}
);

And removing the locate_template from various places like so

if ( ! file_exists(  $dir  ) ) {
	return;
}

Does allow me to create new blocks in the Child theme while retaining the ones in the Parent! However, I don't know the implications of changing this, as we wouldn't want to have others be forced to provide that directory path in the filter.

Using a continue worked for me in this instance from above.

if ( ! file_exists(  $dir  ) ) {
   continue;
}

Let me know your thoughts!

@JeStew
Copy link
Author

JeStew commented Nov 12, 2021

Seeing now that this doesn't work if not using the filter, I'll keep at it and open a PR :)

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

No branches or pull requests

2 participants