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

Timber Error loading template files - existing .twig files not found in spec'd dir path #140

Closed
pgnd opened this issue Apr 9, 2023 · 2 comments

Comments

@pgnd
Copy link

pgnd commented Apr 9, 2023

i've composer-installed a bedrock-scaffold instance of WP

composer create-project roots/bedrock wp.app
...
wp-cli core version
	6.2

wp-cli cli info
	OS:     Linux 6.2.9-200.fc37.x86_64 #1 SMP PREEMPT_DYNAMIC Thu Mar 30 22:31:57 UTC 2023 x86_64
	Shell:  /bin/bash
	PHP binary:     /usr/bin/php
	PHP version:    8.2.4
	php.ini used:   /usr/local/etc/php8/php.ini
	MySQL binary:   /usr/bin/mysql
	MySQL version:  mysql  Ver 15.1 Distrib 10.9.4-MariaDB, for Linux (x86_64) using  EditLine wrapper
	SQL modes:
	WP-CLI root dir:        phar://wp-cli.phar/vendor/wp-cli/wp-cli
	WP-CLI vendor dir:      phar://wp-cli.phar/vendor
	WP_CLI phar path:       /www/wp.app
	WP-CLI packages dir:
	WP-CLI cache dir:       /var/lib/wwwrun/.wp-cli/cache
	WP-CLI global config:
	WP-CLI project config:  /www/wp.app/wp-cli.yml
	WP-CLI version: 2.7.1

i've installed timber & timber/starter-theme,

cd wp.app
composer show | grep -i timber
	timber/timber    2.x-dev 86f9d10    Plugin to write WordPress themes w Objec...

cd wp.app/web/app/themes/timber_s
git branch -a | grep \*
	* 2.x-revert-theme-subfolder
git rev-parse HEAD
	1823e4d0da7e664a674c9c26fc16fa8a3ad069bd

i've created a child theme

cd wp.app/web/app/themes/example-Timber
cat style.css
	/*
	Theme Name:      example-Timber
	Theme URI:       https://example.com/
	Description:     example-Timber Child Theme
	Author:          example.com
	Author URI:      https://example.com/
	Template:        timber_s
	Text Domain:     example-timber-child
	Version:         1.0.0
	*/

functions.php includes,

...
<?php
...
$composer_autoload = ABSPATH . '../../vendor/autoload.php';
if ( file_exists( $composer_autoload ) ) {
	require_once $composer_autoload;
	Timber\Timber::init();
}
...
/**
 * Sets the directories (inside your theme) to find .twig files
 */
Timber::$dirname = array( get_stylesheet_directory() . '/views' );

child theme dir structure is

cd wp.app/web/app/themes/example-Timber
tree
	.
	├── assets
	│   ├── fonts
	│   ├── icons
	│   ├── images
	│   ├── scripts
	│   └── styles
	├── functions.php
	├── index.php
	├── screenshot.png
	├── static
	│   ├── no-timber.html
	│   └── site.js
	├── style.css
	└── views
	    ├── base.twig
	    └── index.twig

it's active

wp-cli theme list --status=parent,active
	+---------------------+--------+--------+---------+
	| name                | status | update | version |
	+---------------------+--------+--------+---------+
	| timber_s            | parent | none   |         |
	| example-Timber      | active | none   | 1.0.0   |
	+---------------------+--------+--------+---------+

where

cat index.php
	<?php

	$context = Timber::context();
	$context['posts'] = '';
	$templates = ['index.twig'];
	if (is_home()) {
	    array_unshift($templates, 'front-page.twig', 'home.twig');
	}
	Timber::render($templates, $context);

on nav to home page,

https://example.com

error, in logs,

==> /var/log/nginx/php-fpm.log <==
[09-Apr-2023 15:38:46 UTC] [ Timber ] Error loading your template files: front-page.twig, home.twig, index.twig. Make sure one of these files exists.

Is usage of Timber::$dirname incorrect or not-sufficient? or a bug?

@szepeviktor
Copy link
Contributor

szepeviktor commented Apr 9, 2023

Hello @pgnd 👋🏻

Maybe 2.x-revert-theme-subfolder branch has a bug ...
It is just a draft PR #139.

@pgnd
Copy link
Author

pgnd commented Apr 9, 2023

@szepeviktor

yup.

i just started setting up for a new dev proj, and wanted to test.

seemed to my read that #139, related to the discuss @ timber/timber#2458, was to be a done deal

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