Undefined variable in \cache\acorn\framework\views\

Getting a bunch of undefined variable errors on Windows - same site builds just fine on Mac - for my variables that are set up in my app\View\Composers. Using Sage/Bud/Acorn.

Including code here:

Composer file: TemplatePrivateSchool.php

<?php

namespace App\View\Composers;

use Illuminate\Support\Collection;
use Roots\Acorn\View\Composer;

use function Roots\asset;

class TemplatePrivateSchool extends Composer
{
    /**
     * List of views served by this composer.
     *
     * @var array
     */
    protected static $views = [
        'templates/private-school',
    ];

    /**
     * Data to be passed to view before rendering.
     *
     * @return array
     */
    public function with()
    {
        return [
            'purposeOf' => $this->getPurposeOfData(),
            'wellRegarded' => $this->getWellRegardedData(),
            'educationalServices' => $this->getEducationalServicesData(),
            'admissions' => $this->getAdmissionsData(),
            'academicProgramsOffer' => $this->getAcademicProgramsOfferData(),
        ];
    }

    /**
     * Data to be passed to view before rendering, but after merging.
     *
     * @return array
     */
    public function override()
    {
        return [
            'heroBackgroundColor' => '#fff',
        ];
    }

    /**
     * Returns "" data.
     *
     * @return array
     */
    public function getPurposeOfData()
    {
        return [
            'content' => 'Lorem ipsum',
        ];
    }

    /**
     * Returns "" data.
     *
     * @return array
     */
    public function getWellRegardedData()
    {
        return [
            'content' => 'Lorem ipsum',
        ];
    }

    /**
     * Returns "" data.
     *
     * @return array
     */
    public function getEducationalServicesData()
    {
        return [
            'heading' => 'Lorem ipsum',
            'content' => 'Lorem ipsum',
        ];
    }

    /**
     * Returns "" data.
     *
     * @return array
     */
    public function getAdmissionsData()
    {
        return [
            'heading' => 'Lorem ipsum',
            'content' => 'Lorem ipsum',
            'image' => [
                'url' => asset(''),
                'alt' => '',
                'title' => '',
            ],
        ];
    }

    /**
     * Returns "" data.
     *
     * @return array
     */
    public function getAcademicProgramsOfferData()
    {
        return [
            'heading' => 'Lorem ipsum',
            'list' => [
                'Lorem ipsum',
            ],
        ];
    }

    /**
     * Returns "" data.
     *
     * @return array
     */
    // public function getData()
    // {
    //     return [
    //         'heading' => '',
    //         'subheading' => '',
    //     ];
    // }
}

Blade file: private-school.blade.php

{{-- Purpose Of --}}
              @if($purposeOf) 
              <div class="relative flex flex-col w-full p-6 text-white rounded-lg bg-blue md:p-12 md:pr-20" data-aos="fade-right">
                {{-- <span class="mx-auto">block</span> --}}
                <div class="prose-lg">{!! $purposeOf['content'] !!}</div>
              </div>
              @endif

File structure:
image

Any ideas why it might not be creating these variables on Windows?

How are you running your site on Windows? Is it with Trellis? If so, are you using WSL?

Yes, using WSL. Currently have it running with Local WP.

:thinking: And also ensure that the same PHP error reporting is enabled for both environments,
maybe the PHP warnings just are not shown, but still occur on both environments?

It actually shows all the content as it should on Mac, there are no errors.

What @strarsis is suggesting is that the errors may be occurring, but not being displayed. Where and how is your error reporting configured on Windows?

I’m just using WP_DEBUG_LOG for both Windows/Mac. Just confirmed it is logging the same error on Windows and logging no error on Mac.

What are the contents of the PHP (rendered Blade-PHP template) file on each environment,
from which the PHP warnings are caused?
Can you compare / post them here? Are the PHP variables inside the same?

Or is there something different in the environment, like the database or a plugin being active or not

The code you’ve shared is working here on LocalWP / WSL2, so I’m thinking the issue may have been introduced in the transfer from Mac → Windows. (If that is the direction you’ve moved the project).

How was the project transferred? Was .gitignore respected?

Sounds like the ServiceProvider for TemplatePrivateSchool isn’t booting. Does clearing the config cache via wp acorn config:clear fix the issue?

Oh, and also double check your post-autoload-dump setup. I can imagine that not running could cause issues if the cache has been brought across.

We have developers who are working on it on both Mac and PC at the moment. Everything loads fine with the same files/setup/all using the same git on Mac, but on PC, we just see those variable errors for everything. And this is spanning across all of our Sage projects that are using Composers.

Edit: Did try clearing the cache, cleaning the views, and adding in that post-autoload dump to no avail. :frowning:

This sounds like a filename/namespace case sensitivity issue since you’re using Windows itself (mentioned by @EHLOVader on our Discord server)

You said you’re using WSL, but the paths in your OP suggest otherwise (C:\ ...). This topic from the Local community covers how to install Local within WSL

2 Likes

Yeah, I was thinking it might have something to do with the fact that it’s not in the WSL network folder. It will let me launch/use WSL in VS Code for projects not in that folder, but builds are usually extremely slow. I did try to move the project folder on my local (still using LocalWP) from the LocalSites folder to a space in the WSL network folder, but LocalWP popped up an error that a Local site can’t be placed in a Network folder, so i’m thinking this might be a LocalWP limitation.

Will try following those Local WSL installation instructions and report back!

Happy to say this worked! Thanks a ton.

1 Like