<p>In order to render a template within your custom plugin you need to include your plugin handle in front of your template path. For example</p>

<pre><code>plugin-handle/_components/fields/Regionselect_settings
</code></pre>

CC BY-SA 4.0
2018-09-20T21:09:13.433Z
2018-09-20T21:09:13.433Z
Robin Schambach
<p>I'm trying to build a simple dropdown field with a pre-populated set of options, so I figured I'd just import most of the methods from Craft's native Dropdown field. The plugin name is <code>siteutilities</code> and the field name is <code>Regionselect</code>:</p>

<pre><code>namespace kgrote\siteutilities\fields;

use kgrote\siteutilities\SiteUtilities;

use Craft;
use craft\base\ElementInterface;
use craft\fields\BaseOptionsField; 
</code></pre>

<p>This pulls in the code from <code>craft/vendor/craftcms/cms/src/fields/BaseOptionsField.php</code>.</p>

<p>So now I want to render a custom settings template for my plugin:</p>

<pre><code>public function getSettingsHtml()
{
    return Craft::$app-&gt;getView()-&gt;renderTemplate(
        '_components/fields/Regionselect_settings',
        [
            'field' =&gt; $this,
        ]
    );
}
</code></pre>

<p>But I get a Twig error:</p>

<blockquote>
  <p>Unable to find the template
  “_components/fields/Regionselect_settings”.</p>
</blockquote>

<p>My plugin file structure looks like this:</p>

<pre><code>kgrote
|-siteutilities
  |-src
    |-fields
    |  |-Regionselect.php
    |-templates
    |  |-_components
    |    |-fields
    |      |-Regionselect_settings.html
    |-SiteUtilities.php
</code></pre>

CC BY-SA 4.0
2018-09-19T22:07:59.823Z
It searches for your template as well. Are you sure it's the correct path? Do you use a custom module instead of a plugin eventually?
Robin Schambach
CC BY-SA 4.0
2018-09-20T19:57:05.640Z
@RobinSchambach I think so, I've updated the question with my plugin's file structure. And no I don't use a custom module, just a plugin.
kmgdev
CC BY-SA 4.0
2018-09-20T19:58:27.953Z
Why a php file? You can only render twig and html files. All others won't be parsed/proceed by Twig
Robin Schambach
CC BY-SA 4.0
2018-09-20T20:01:43.137Z
@RobinSchambach Sorry that was a typo, it's a HTML file, I've updated the question.
kmgdev
CC BY-SA 4.0
2018-09-20T20:48:23.140Z
You need to include your plugin handle at the first position `plugin-handle/_components/fields/Regionselect_settings`
Robin Schambach
CC BY-SA 4.0
2018-09-20T21:07:16.827Z
@RobinSchambach Ah ha! That did it! If you want to post it as an answer I'll mark it accepted.
kmgdev
CC BY-SA 4.0
2018-09-20T21:09:48.410Z
Sorry for being so slow. I somehow overview that mistake at the first sight.
Robin Schambach
<plugin-development><custom-fieldtype>
Custom Plugin Field Using Wrong Template Path
# Custom Plugin Field Using Wrong Template Path

(Asked by: username_0 on 2018-09-19)

I'm trying to build a simple dropdown field with a pre-populated set of options, so I figured I'd just import most of the methods from Craft's native Dropdown field. The plugin name is siteutilities and the field name is Regionselect:
namespace kgrote\siteutilities\fields;

use kgrote\siteutilities\SiteUtilities;

use Craft;
use craft\base\ElementInterface;
use craft\fields\BaseOptionsField; 

This pulls in the code from craft/vendor/craftcms/cms/src/fields/BaseOptionsField.php.
So now I want to render a custom settings template for my plugin:
public function getSettingsHtml()
{
    return Craft::$app->getView()->renderTemplate(
        '_components/fields/Regionselect_settings',
        [
            'field' => $this,
        ]
    );
}

But I get a Twig error:

Unable to find the template
  “_components/fields/Regionselect_settings”.

My plugin file structure looks like this:
kgrote
|-siteutilities
  |-src
    |-fields
    |  |-Regionselect.php
    |-templates
    |  |-_components
    |    |-fields
    |      |-Regionselect_settings.html
    |-SiteUtilities.php

**Tags:** plugin-development, custom-fieldtype
> **Comments:**
> **username_1**: It searches for your template as well. Are you sure it's the correct path? Do you use a custom module instead of a plugin eventually?  
> **username_0**: @RobinSchambach I think so, I've updated the question with my plugin's file structure. And no I don't use a custom module, just a plugin.  
> **username_1**: Why a php file? You can only render twig and html files. All others won't be parsed/proceed by Twig  
> **username_0**: @RobinSchambach Sorry that was a typo, it's a HTML file, I've updated the question.  
> **username_1**: You need to include your plugin handle at the first position `plugin-handle/_components/fields/Regionselect_settings`  
> **username_0**: @RobinSchambach Ah ha! That did it! If you want to post it as an answer I'll mark it accepted.  
> **username_1**: Sorry for being so slow. I somehow overview that mistake at the first sight.  

---

## 1 answers

### Answer by username_1 on 2018-09-20. Score: 1 | Accepted answer

In order to render a template within your custom plugin you need to include your plugin handle in front of your template path. For example
plugin-handle/_components/fields/Regionselect_settings


---

