Passing data between filters and templates not working

Hello everybody :smiley:

i’m having some issue while trying to use Sage 9 for the first time.
Specifically, it seems that no matter what I try there’s no way to get any values from the $data array inside the template.

I’ve stepped trough the code with xdebug, and I can confirm the filter gets properly registered with the right template, but once the debugging process reaches the template there’s no trace of $data in the stack. Both $data and the contents of the array are undefined.

here’s the call:


namespace App;

add_filter('sage/template/template-bottega/data', function () {
$data = [
    'people' => [
        'nome' => 'Nome 1',
        'descrizione' => 'Descrizione 1',
        'foto' => 'https://www.bottega.local/wp-content/example.png',
        'ruolo' => 'Cuoco'
return $data;

in views/template-bottega.blade.php

  Template Name: Bottega


<h1>{{ $people }}</h1>
  @while(have_posts()) @php the_post() @endphp

Other than a “Undefined Variable Error” All I get is the following exception:
Illuminate\Contracts\Container\BindingResolutionException: Target [Illuminate\Contracts\Container\Container] is not instantiable while building [Illuminate\Events\Dispatcher].

Any help would be appreciated.


You may want to see Sage 9 - Passing ACF data via Blade not working for an explanation of what’s going on.

This is supposedly fixed in Sage 9.0.1, but there are a few things that will need to be updated. You can try manually applying the changes at by stepping through each incremental change. Here’s the breakdown:

in /app/controllers/, rename the files app.php -> App.php and front-page.php -> FrontPage.php.

In these two renamed files, change this line:

namespace App;


namespace App\Controllers;

Finally, in the file composer.json at the root of the theme, replace this line:

"soberwp/controller": "~9.0.0-beta.4"


"soberwp/controller": "2.0.1"

You can then run composer require soberwp/controller:2.0.1 from the command line to force the update.

Give this a try and see if it resolves your problem! This has not yet been patched into the current release of Sage 9 as far as I can tell.

1 Like