Returning blade templates from Controller

In a Sage 9x theme. I have a layout partial that will include different partials based on the post type or template.

I’d love to move this logic to a controller and have the public function return the desired template.

I’ve seen posts using App\template(‘blade.file’). However these answers I am assuming are from before the namespacing for controllers changed. When I try the above, I get a namespace error.

Any idea how I can access the template function from inside my controller post namespace changing to App\Controllers?

I’ve tried App\Controllers\template() but no luck.

Hi @rguttersohn!

Just a thought - have you tried \App\template('blade.file') ?

Omitting the leading slash will resolve the namespace as a child of your current namespace. For example, if you have code like this:

namespace Foo;
$obj = new Bar\Baz();

This will try to create an instance of Foo\Bar\Baz(). Whereas:

namespace Foo;
$obj = new \Bar\Baz();

Will resolve to Bar\Baz().

That did the trick! Thanks so much.