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->getBasePath().DIRECTORY_SEPARATOR.'templates')) {
$e->roots[$this->id] = $baseDir;
}
});
In my init() function I have this
Event::on(
Cp::class,
Cp::EVENT_REGISTER_CP_NAV_ITEMS,
function(RegisterCpNavItemsEvent $event) {
$event->navItems[] = [
'url' => 'leads',
'label' => '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
'*' => [
'modules' => [
'leads-module' => [
'class' => \modules\leadsmodule\LeadsModule::class,
],
],
'bootstrap' => ['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