Using Sage theme through symbolic link causes errors

Hey everyone,

So I usually setup my local development environment in a way where I create a new site using Local, which on my Mac means the Wordpress root is at ~/Local Sites/$SITE_NAME/app/public. But I tend to prefer to have my actual working files in another directory (~/freelance/$CLIENT/$THEME_NAME) and so usually I include the theme in the Local site by creating a symbolic link. This works just fine using a more standard Wordpress theme structure, but when I try to do this with a Sage (+ Acorn) theme I keep getting cryptic errors like so:

InvalidArgumentException: Unrecognized extension in file: ~/Local Sites/$SITE_NAME/app/public

The only way I have been able to fix this error is if I don’t use a symbolic link and instead really have the theme files at ~/Local Sites/$SITE_NAME/app/public/wp-content/themes/$THEME_NAME. But I would really prefer not to have to do that, because it makes keeping track of projects more difficult.

I’ve spent multiple hours trying to track down this issue through XDebug without success.
The only thing I’ve figured out is that the symbolic linking might result in invalid relative paths when Sage tries to resolve paths to template files. But not completely sure about that.

So I’m wonder if anyone has gotten a similar setup working?

Thanks for any help!

Probably because Local uses Containers, into which extra directories have to be mapped,
this guide may be useful:

1 Like

Thanks for replying strarsis, but unfortunately this did not help. The article describes the same method I’ve been using, creating a symlink from the Local site’s folder to where my theme is located. And as said this works just fine with non Sage themes, so the problem is Sage specific.

I figured it out!
The problem is in the Roots\Acorn\Sage\ViewFinder class constructor line 44:

$this->path = $path ? realpath($path) : get_theme_file_path();

The $path constructor argument is always null, so get_theme_file_path() is used, which points at the theme directory but does not resolve into the true path of the symlink.
The $this->path variable is then used in ViewFinder::getRelativeViewPaths to create relative paths to view files which have been passed through the realpath method. This results in invalid relative paths.
To solve this issue I changed line 44 to always use realpath:

$this->path = realpath($path ?: get_theme_file_path());

No more errors! Of course I don’t know the code base very well, so this may cause some other issues, but after some quick testing it seems to work.

2 Likes