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

            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









Still get a 404 template not found: leads when accesses /admin/leads from the control panel

1 Answer 1


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

  • In config/app i'm using 'leads-module'. I've tried putting inside the module folder /admin/leads-module/leads and still get Template not found: leads. I've also put it in the regular templates folder in root and still get the same error. Can you show me a working example using the pluginfactory.io link? Mar 21, 2019 at 15:23
  • i've edited my question showing combos of template paths i've used Mar 21, 2019 at 15:48
  • Not really sure what I should show. Your basic code is correct, you just should not append .twig to the url. just typing admin/leads-module/leadsshould show you the correct template if it's not empty Mar 21, 2019 at 15:54
  • 1
    Oh I misunderstood, I thought those were template paths rather than urls. I got it to work by accessing the URI /admin/leads-module/leads which corresponds to the template path /src/templates/leads.twig. Mar 21, 2019 at 15:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.