Sage 10 and component template & class subfolders

How can I use a subfolder for a component template file and the class file in sage 10?

From the blade docs, I found that I can call a component within a subfolder with a dot notation. So something like

<x-subfolder.test-component />

For a component template in resources/views/components/subfolder/test-component.blade.php

The component is correctly called this way, but I can’t figure out how to make the class model in View/Components/Subfolder/TestComponent.php connect to the component template.

All variables not directly passed to the component via attributes are undefined. I’m probably messing something with the class name when moving the file, but maybe someone has done something similar already and knows how it works?

An easy way to reproduce this is to move the example Alert component and class file into a subfolder, and the types variable that is only defined in the Alert class will be undefined in the component.

I’ve made the Alert move that you say and everything works ok.

Maybe, I’m assuming you haven’t changed the namespace of the component class. So, after I moved the Alert.php to test folder the namespace in Alert.php now becomes:

namespace App\View\Components\Test;

1 Like

The template file a Component uses is defined in the component’s class file in the render() method (see line 55 in Alert.php). They aren’t autoloaded like Composers. You’re getting the results you’re seeing because Blade also allows defining what it calls an “anonymous component,” which has no class file.

Thanks a lot! I forgot the namespace