flyntwp / flynt-starter-theme

The starter theme for building Flynt projects.
MIT License
69 stars 4 forks source link

Timber loaded gets confused on Windows Apache Server #235

Closed bdbch closed 6 years ago

bdbch commented 7 years ago
Feature

TimberLoader

Webserver Stack
System

Windows 10

Problem

I presume that Windows backslashes are confusing Timber and the TimberPaths set for loading the files. We tried using realpath in combination with str_replace to replace all forward slashes with backslashes but it didn't help fixing the problem.

The only solution was to directly load the index.twig inside the Timber::fetch function here. Looks like on Windows Timber doesn't care about the full path but rather uses the paths defined via returnTimberPaths directly.

Couldn't figure out a solution yet or really pinpoint down a 100% proof of what is causing this, I'll reinvestigate this, but as I said using index.twig instead of $filePath here on Windows helped fixing it.

dgrdl commented 7 years ago

What exactly do you mean by "confusing Timber"? I'm guessing it isn't rendering anything? Is there an error message?

Either way, generally speaking you don't need to replace forward slashes with backslashes, since PHP should work with forward slashes irrespective of the operating system.

bdbch commented 7 years ago

Yes there is an error message saying that the twig file could not be found, even though the path is correct. This is fixed as soon as I just use index.twig without any path in front of it.

o1y commented 6 years ago

This is not only limited to Windows systems or Apache-Servers. Twigs Filesystem loader always combines the loader path with the filename. Not sure if this has been changed at some time ...

Unfortunately, there is no longer an exception thrown in newer versions of Timber, so this issue becomes very confusing, because Timber isn't rendering any component at all. It would be nice to see a merge of this pull request soon! :)

dgrdl commented 6 years ago

After some more digging, I found that the root cause for this error is the PHP ini setting for open_basedir, which Timber checks here: https://github.com/timber/timber/blob/master/lib/Loader.php#L138

On systems not using this setting (default is NULL), everything should work fine since the root path ('/') in the Timber loader is not modified.

Since I would rather not set the file to be fetched to just be index.twig (this file could exist in any path added to the timber/loader/paths hook), I have made a separate PR for this fix (#265) using a relative path instead.

bdbch commented 6 years ago

Awesome, no more manually fixes on project init. Good job!

bdbch commented 6 years ago

Do we have an update on the PR?

dgrdl commented 6 years ago

Merged into master with v0.4.0