Closed mattverb closed 1 month ago
Further to this, I have enabled WP Debug & Logging and these are the errors I am getting:
[26-Jan-2024 12:25:03 UTC] [ Timber ] Error loading your template files: C:/laragon/www/liverpool-womens-hospital/wp-content/themes/liverpool-womens/theme/blocks/hero/index.twig. Make sure one of these files exists.
[26-Jan-2024 12:25:03 UTC] [ Timber ] Error loading your template files: C:/laragon/www/liverpool-womens-hospital/wp-content/themes/liverpool-womens/theme/blocks/example-hero/index.twig. Make sure one of these files exists.
[26-Jan-2024 12:25:03 UTC] [ Timber ] Error loading your template files: C:/laragon/www/liverpool-womens-hospital/wp-content/themes/liverpool-womens/theme/blocks/example/index.twig. Make sure one of these files exists.
When clicking on the file locations however, they do exist and are the correct path? Very confused why they wouldn't be loading in.
Hi! I'm pretty sure this has to do with paths on Windows, but I don't have a Windows machine to test it. I'll see what I can find out and try to have something for you to test.
Hi! I'm pretty sure this has to do with paths on Windows, but I don't have a Windows machine to test it. I'll see what I can find out and try to have something for you to test.
Thank you! I've tried both relative and non-relative URLs. It's very strange, I use a very similar setup on another theme (adapted version of Timber Starter Theme) and have no issues. If we could get this working that would be amazing, your theme setup is much cleaner & more reliable than the one I'm currently using.
Hi @cearls is there any update on this at all?
Hi @mattverb, can you try replacing the following function in functions.php with the code I've included below? I'm hoping the use of DIRECTORY_SEPARATOR
will make it compatible with Windows.
public function acf_register_blocks()
{
$blocks = [];
foreach (new DirectoryIterator(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'blocks') as $dir) {
if ($dir->isDot()) continue;
if (file_exists($dir->getPathname() . DIRECTORY_SEPARATOR . 'block.json')) {
$blocks[] = $dir->getPathname();
}
}
asort($blocks);
foreach ($blocks as $block) {
register_block_type($block);
}
}
I've run into this issue when transferring a site to hosting (a couple of times), in that instance it's an issue with open basedir so you might want to look into that. In my instance, I had to open up open_basedir to get the templates to load.
Hi everybody! I'm trying out timberland on a Windows machine using Laragon, and I've recently came across this issue, timber won't load the index.twig template file. It has something to do with Timber and Windows file paths, I managed to get it working changing the acf_block_render_callback on functions.php to the code below:
function acf_block_render_callback( $block, $content ) {
$context = Timber::context();
$context['post'] = Timber::get_post();
$context['block'] = $block;
$context['fields'] = get_fields();
$slug = str_replace( 'acf/', '', $block['name'] );
$template = 'blocks/' . $slug . '/index.twig';
Timber::render( $template, $context );
}
Had the same issue too on laragon on windows. Submitted a pull request with a relative fix for path.
Thanks @chiisai-kaeru and @zync09! I'll review the PR and get it merged.
You're welcome @cearls, and thanks to @zync09 also!
I'm trying to create a new block within the theme folder but it's not being registered on the front-end when I load it in via Guttenberg. The example blocks loads into the site no issue, but registering new blocks just seems to not work at all.
It's worth noting that the block is registered in ACF, and can assign fields to the block.
Theme's functions.php
Hero Block index.twig:
block.json:
Page.twig