<p>It must be <code>/admin/module-id/leads</code>. So in your case maybe <code>/admin/leadsmodule/leads</code> or <code>/admin/leads-module/leads</code> depending on your ID if you want to access it directly via template route.</p>

<p>Otherwhise you need to create custom URL rules</p>

CC BY-SA 4.0
2019-03-21T15:23:07.547Z
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?
millman2394
CC BY-SA 4.0
2019-03-21T15:48:30.273Z
i've edited my question showing combos of template paths i've used
millman2394
CC BY-SA 4.0
2019-03-21T15:54:03.683Z
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/leads`should show you the correct template if it's not empty
Robin Schambach
CC BY-SA 4.0
2019-03-21T15:58:51.517Z
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`.
millman2394
CC BY-SA 4.0
2019-03-21T15:11:56.653Z
2019-03-21T15:11:56.653Z
Robin Schambach
<p>I've used this tool to generate a module: <a href="https://pluginfactory.io/" rel="nofollow noreferrer">https://pluginfactory.io/</a></p>

<p>So in my constructor, I have</p>

<pre><code> 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;
            }
        });
</code></pre>

<p>In my init() function I have this</p>

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

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

<p>My template folder is located at <code>modules/leadsmodule/src/templates</code></p>

<p>Inside templates I have a file called <code>leads.twig</code>.</p>

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

<p>I need my control panel item to load a specific template.</p>

<p>What am I doing wrong?</p>

<hr>

<p>Edit: the control panel URI for my item looks like <code>/admin/leads</code></p>

<p>Here is my config/app.php</p>

<pre><code>'*' =&gt; [
        'modules'   =&gt; [
            'leads-module' =&gt; [
                'class' =&gt; \modules\leadsmodule\LeadsModule::class,
            ],
        ],
        'bootstrap' =&gt; ['leads-module'],
    ],
</code></pre>

<p>I've tried every combination to load the template I can think of.</p>

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

<pre><code>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
</code></pre>

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

<modules>
Modules - CP Template not found
# Modules - CP Template not found

(Asked by: username_0 on 2019-03-21)

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

**Tags:** modules

---

## 1 answers

### Answer by username_1 on 2019-03-21. Score: 4 | Accepted answer

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

> **Comments:**
> **username_0**: 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?  
> **username_0**: i've edited my question showing combos of template paths i've used  
> **username_1**: 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/leads`should show you the correct template if it's not empty  
> **username_0**: 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`.  

---

