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

Block not being rendered #43

Open
MitchJackson94 opened this issue Jan 19, 2021 · 9 comments
Open

Block not being rendered #43

MitchJackson94 opened this issue Jan 19, 2021 · 9 comments
Labels
bug Something isn't working

Comments

@MitchJackson94
Copy link

MitchJackson94 commented Jan 19, 2021

I have added my block template in my own folder and used 'timber/acf-gutenberg-blocks-templates' to assign it to my custom folder I can see the block it in the Gutenberg editor and add content to it however the block is not being rendered on my homepage.

templates/blocks/hero.twig

{#
  Title: Hero
  Description: Add hero to a page
  Category: formatting
  Icon: editor-paste-text
  Keywords: hero
#}

<div class="hero {{ classes }}" data-{{ block.id }}>
    <h1>{{ fields.hero_title }}</h1>
    <div>
        {{ fields.hero_text }}
    </div>
</div>

pages/page.twig

{% extends 'layouts/base.twig' %}

{% block body %}
    {{ post.content }}
{% endblock body %}
@palmiak
Copy link
Owner

palmiak commented Jan 19, 2021 via email

@MitchJackson94
Copy link
Author

Screenshot 2021-01-19 at 11 22 42 pm

functions.php

<?php

/**
 * Jackpine
 *
 * Based on the Timber starter theme.
 * Huge thanks to the folks who made the tools that Jackpine is built on.
 *
 * @package WordPress
 * @subpackage Jackpine
 * @since Jackpine 0.1.0
 */

require_once dirname( __DIR__ ) . '/vendor/autoload.php';

function add_to_context( $context ) {
    $context['primary_menu']  = new Timber\Menu('Primary');
    $context['footer_menu'] = new Timber\Menu('Footer');

    return $context;
}

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

add_filter( 'timber/context', 'add_to_context' );

use Jackpine\JackpineSite;

new JackpineSite( 'jackpine', '0.11.0', '../dist', '../assets/templates' );

I'm using a starter theme called JackPine

@palmiak
Copy link
Owner

palmiak commented Jan 19, 2021 via email

@palmiak palmiak added the bug Something isn't working label Jan 21, 2021
@palmiak
Copy link
Owner

palmiak commented Jan 21, 2021

One more thing - which ACF version and which Gutenberg version (plugin or the one built in core)?

@MitchJackson94
Copy link
Author

I'm using the composer versions of ACF on version 5.9.3 I'm using the core version of Gutenberg on WordPress 5.6 also using bedrock if that's any help.

@palmiak
Copy link
Owner

palmiak commented Jan 21, 2021

Hi @MitchJackson94

So I was able to replicate it and I understand why this is happening. I even have a plan how to fix it.

Overall this is caused by the structure - Timber::$dirname is set to ../assets/templates/ and the directory is set there too. So it tries to find a block in ../assets/templates/../assets/templates/blocks.

I'm thinking about adding (this a rough draft, as it doesn't respect the $dirname as array yet) something like this:

foreach ( $ret as $dir ) {
	$timber_dir[] = str_replace( Timber::$dirname, '', $dir );
}

I have to finish working with one PR and I'll try to fix this.

@MitchJackson94
Copy link
Author

Thanks for the update it makes sence now.

Is there a quick and dirty way of getting it working?

@palmiak
Copy link
Owner

palmiak commented Jan 22, 2021

Adding:

foreach ( $ret as $dir ) {
	$timber_dir[] = str_replace( Timber::$dirname, '', $dir );
}

return $timber_dir;

after:

foreach ( $directories as $directory ) {
				if ( $is_example ) {
					$ret[] = $directory . "/{$slug}{$example_identifier}.twig";
				}
				if ( $is_preview ) {
					$ret[] = $directory . "/{$slug}{$preview_identifier}.twig";
				}
				$ret[] = $directory . "/{$slug}.twig";
			}

and remove the previous return.

As a quick and dirty it should work ;)

@MitchJackson94
Copy link
Author

Got it working thanks 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants