Has anyone worked with composers in the roots.io/sage?

[ad_1]

Hi,

I created a Gutenberg block called “example-block,” and its view is located at `views/blocks/example-block.blade.php`. The static rendering of the template is working, and using ACF functions like `get_field()` displays the field content as well.

I decided to use Composers, so I created a Composer named `ExampleBlockComposer.php`:

“`php
<?php

namespace App\View\Composers;

use Roots\Acorn\View\Composer;

class ExampleBlockComposer extends Composer
{
/**
* List of views served by this composer.
*
* @var string[] */
protected static $views = [
“blocks.example-block”
];

public function with(){
return [
“roots”=> “Modern WordPress Development”
];
}
}
“`

If I specify `$views = [“*”];`, it works fine. But when I specify a single block as in the above code snippet, and access the variable `$roots` in blocks/example-block.blade.php I get this error: `Undefined variable $roots (View: /var/www/html/web/app/themes/portfolio/resources/views/blocks/example-block.blade.php) (View: /var/www/html/web/app/themes/portfolio/resources/views/blocks/example-block.blade.php).`

[ad_2]

 

This site will teach you how to build a WordPress website for beginners. We will cover everything from installing WordPress to adding pages, posts, and images to your site. You will learn how to customize your site with themes and plugins, as well as how to market your site online.

Buy WordPress Transfer