Cannot get Composers to work

I’m trying to do the most basic things in Sage 10 and it’s just not working.

I wanted to try out creating a composers to pass some data to a partial.

Here is my Composer

// app/Composers/ExampleThing.php
<?php
namespace App\Composers;

use Roots\Acorn\View\Composer;

class ExampleThing extends Composer
{
    protected static $views = [
        'partials.example-partial',
    ];
    public function with($data, $view)
    {
        return ['example' => "this is the content of a composer."];
    }
}

And here is my partial

<!-- resources/views/partials/example-partial.blade.php -->
<div>
    {{ $example }}
</div>

But when I try and include the partial anywhere, i get this…

I have no idea what I’m doing wrong because I only adapted code from the docs.

This works:

<?php

namespace App\View\Composers;

use Roots\Acorn\View\Composer;

class ExampleThing extends Composer
{
    protected static $views = [
        'partials.example-partial',
    ];
    public function with()
    {
        return ['example' => "this is the content of a composer."];
    }
}

I could of sworn I tried that! :joy:

sorry and thank you

1 Like

The Acorn WP-CLI commands make it so you don’t have to think about it:

$ wp acorn make:composer ExampleThing