Problems when trying to create a block that has a blade template in a subfolder

I want to put acf blocks in deeper folder but then for some reason, fields does not get assigned.

so for example i have a block class that looks like this:

<?php

namespace App\Blocks\about;

use Log1x\AcfComposer\Block;
use Roots\Acorn\Application;
use StoutLogic\AcfBuilder\FieldsBuilder;

class Herox extends Block
{
    public function __construct(Application $app)
    {
        $this->name = __('Herox', 'sage');
        $this->slug = 'about-herox';
        $this->category = 'blocks';
        $this->icon = 'editor-ul';
        $this->keywords = [
            'hero',
        ];

        parent::__construct($app);
    }

    public function fields(): FieldsBuilder|array
    {
        $builder = new FieldsBuilder('about-herox');

        $builder
            ->addText('titlex');

        return $builder->build();
    }

    public function with(): array
    {
        return [
            'title' => get_field('title'),
        ];
    }
}

and in this case it works fine, it takes the blade file from

:web/app/themes/my-theme/resources/views/blocks/about-herox.blade.php

but i wanted to move the blade block to its own folder like this:

:web/app/themes/my-theme/resources/views/blocks/about/herox.blade.php

in this case, i changed the slug to: $this->slug = ‘about.herox’; and the template worked, but when i try to edit fields in it, it says that the fields are not defined. What could be the problem, sorry if it’s a rookie mistake im making, but i want to find the solution. (tried the gpt but it didn’t helped)

thanks!

You will need to add the $view property to your block and set it to blocks.about.herox (dot-notation for your block view path).

You should also capitalize About in your namespace.

- namespace App\Blocks\about;
+ namespace App\Blocks\About;
1 Like

Thank you for you fast response. Sadly it didn’t helped.
the blade view is being found automatically, but the problem is that it does not find the decalred fields:

    public function fields(): FieldsBuilder|array
    {
        $builder = new FieldsBuilder('about.herox');

        $builder
            ->addText('titlex');

        return $builder->build();
    }

I did tried multiple namings like just herox or about.herox but the problem keeps persisting

oh nevermind i misunderstood the $view, i used $this->view before. anyway thank you very much, it worked!