Modules - CP Template not found I've used this tool to generate a module: https://pluginfactory.io/

So in my constructor, I have

 Event::on(View::class, View::EVENT_REGISTER_CP_TEMPLATE_ROOTS, function (RegisterTemplateRootsEvent $e) {
            if (is_dir($baseDir = $this-&gt;getBasePath().DIRECTORY_SEPARATOR.'templates')) {
                $e-&gt;roots[$this-&gt;id] = $baseDir;
            }
        });


In my init() function I have this

 Event::on(
            Cp::class,
            Cp::EVENT_REGISTER_CP_NAV_ITEMS,
            function(RegisterCpNavItemsEvent $event) {
                $event-&gt;navItems[] = [
                    'url' =&gt; 'leads',
                    'label' =&gt; 'Leads Management'
                ];
            }
        );


When I click the link on the control panel, I will get a Template Not Found error.

My template folder is located at modules/leadsmodule/src/templates

Inside templates I have a file called leads.twig.

I did die() on the $baseDir that it's being set to in the constructor and got the path: modules\leadsmodule\src\templates

I need my control panel item to load a specific template.

What am I doing wrong?



Edit: the control panel URI for my item looks like /admin/leads

Here is my config/app.php

'*' =&gt; [
        'modules'   =&gt; [
            'leads-module' =&gt; [
                'class' =&gt; \modules\leadsmodule\LeadsModule::class,
            ],
        ],
        'bootstrap' =&gt; ['leads-module'],
    ],


I've tried every combination to load the template I can think of.

In side my modules/leadmodule/src/templates I've placed the following

admin/leads-module/leads.twig

admin/leadsmodule/leads.twig

/admin/leads.twig

/leads-module/admin/leads.twig

/leads-module/leads.twig

/leadsmodule/admin/leads.twig

/leadsmodule/leads.twig

/leads.twig


Still get a 404 template not found: leads when accesses /admin/leads from the control panel
It must be /admin/module-id/leads. So in your case maybe /admin/leadsmodule/leads or /admin/leads-module/leads depending on your ID if you want to access it directly via template route.

Otherwhise you need to create custom URL rules