So I’m building a plugin (using Clover as a base) and trying to use Sage 10 as a reference for how to structure
Inside PluginNameServiceProvider->boot() I call the following to setup a namespace for the blade views inside the plugins context…
public function boot()
{
if ( function_exists( '\Roots\view' ) ) {
$view = \Roots\view();
$view->addNamespace('MyNamespace', __DIR__ . '/../../resources/views/');
}
}
As a result, I can use Roots\view inside a provider to return & parse a blade file in the plugin directory …
return \Roots\view('MyNamespace::app')->render();
app.blade.php is stored as you’d expect in plugin/resources/views/app.blade.php
I’ve then created a controller/View composer in plugin/src/View/Composers/App.php
Contents as:
<?php
namespace PluginNamespace\View\Composers;
use Roots\Acorn\View\Composer;
class App extends Composer
{
protected static $views = [
'*',
];
public function with()
{
return [
'withtest' => 'test passed',
];
}
}
but the controller isnt getting picked up and passing data to the view from the array returned from with
Any idea how im should attach the controller?
I suspect I'm going about this backwards and I should somehow be instantiating a view composer and then using this to render an associated view ?!
Whilst this “works” - I’m still interested to find out if theres a more correct way of doing things inside Clover / Acorn as I cant find any official documentation to guide me.
Thanks for the guidance Log1x - yeh I was just peeking into the ViewServiceProvider, attachComposers and thinking I might be able to do $this->app->view or something but also wasnt sure if I had to extend a certain class to get that to work.
I’m using a really old plugin (wp-router) to generate routes at the moment - do you know if there’s anything in Acorn I can be making use of to do the same and make custom routes or can recommend a preferred package?
Essentially made a RouteServiceProvider that does this: