Answers.Body: <p>Craft will only check for templates in your plugin’s templates/ folder during CP and action requests. When you start routing to your controller action via a site-facing route, it’s no longer either one of those; it’s just a normal Site request. So you will need to point Craft to your plugin’s templates folder explicitly.</p>
  
  <pre><code>// Point Craft to this plugin's templates/ folder
  $templatesPath = craft()-&gt;path-&gt;getPluginsPath().'myplugin/templates/';
  craft()-&gt;path-&gt;setTemplatesPath($templatesPath);
  
  // Render and output the template
  $this-&gt;renderTemplate('_mytemplate', $variables);
  </code></pre>
  
  <p>Note that it will no longer be necessary to include your plugin’s handle in the template path.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-09-03T10:48:12.903Z
Answers.Text: Because I no longer need the plugin's handle in the template path, I also have to remove it from `extends` tags in the template. Which is fine, except when the layout I'm extending `extends` a layout from my main (non-plugin) templates. It now can't find that layout, because it's looking in my plugin templates.
Answers.UserDisplayName: Phil Gyford
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-09-03T20:24:21.230Z
Answers.Text: @PhilGyford Yeah if you go this route, you can only include templates that live inside the directory passed into setTemplatesPath(). No way around that currently.
Answers.UserDisplayName: Brandon Kelly
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-06-30T18:38:49.693Z
Answers.Text: Minor typo in your solution, it should apparently be `craft()->path->setTemplatesPath`... Other than that, it worked perfectly! Thanks Brandon!
Answers.UserDisplayName: Lindsey D
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-06-30T11:03:08.267Z
Answers.LastActivityDate: 2014-06-30T18:58:23.410Z
Answers.LastEditDate: 2014-06-30T18:58:23.410Z
Answers.UserDisplayName: Brandon Kelly
Body: <p><strong>This may be a bug...</strong></p>
  <p>I have a controller action which has been working great. It's a simple action with a single purpose... load a template with an internal value.</p>
  <pre><code>public function actionMyAction()
  {
      $this-&gt;renderTemplate('myplugin/_mytemplate', array(
          'internalVar' =&gt; craft()-&gt;myPlugin-&gt;internalVar
      ));
  }
  </code></pre>
  <p>When I call that action via a simple URL, everything loads flawlessly:</p>
  <blockquote>
  <p>mywebsite.com/actions/myPlugin/myAction</p>
  </blockquote>
  <p><strong>Here's where it gets interesting...</strong></p>
  <p>So I just discovered the <a href="http://buildwithcraft.com/docs/plugins/hooks-reference#registerSiteRoutes" rel="nofollow noreferrer">registerSiteRoutes</a> hook. It looks awesome, and would make accessing my special page that much easier for a front-end user!</p>
  <p>Here's how I implemented it in my <code>MyPluginPlugin.php</code> file:</p>
  <pre><code>public function registerSiteRoutes()
  {
      return array(
          'myroute' =&gt; array('action' =&gt; 'myPlugin/myAction')
      );
  }
  </code></pre>
  <p><strong>The good news is,</strong> the route is properly followed, and my controller action gets loaded.</p>
  <p><strong>The bad news is,</strong> suddenly the template that's supposed to be loaded can't be found. :(</p>
  <blockquote>
  <p><strong>Template Error</strong></p>
  <p>Unable to find the template &quot;myplugin/_mytemplate&quot;.</p>
  </blockquote>
  <p>So does anyone know, <strong>what's going on here?</strong> I know that the <code>renderTemplate</code> method does some minor rewriting of the template path, but why would it be different when accessing via a front-end route?</p>
  
Tags: <plugin-development><controller><routes>
Title: Is the "registerSiteRoutes" hook screwing up my template path?
ThreadText: # Is the "registerSiteRoutes" hook screwing up my template path?
  
  (Asked by: username_0 on 2014-06-30)
  
  **This may be a bug...**
  
  I have a controller action which has been working great. It's a simple action with a single purpose... load a template with an internal value.
  
  ```
  public function actionMyAction()
  {
      $this->renderTemplate('myplugin/_mytemplate', array(
          'internalVar' => craft()->myPlugin->internalVar
      ));
  }
  
  ```
  
  When I call that action via a simple URL, everything loads flawlessly:
  
  > mywebsite.com/actions/myPlugin/myAction
  
  **Here's where it gets interesting...**
  
  So I just discovered the [registerSiteRoutes](http://buildwithcraft.com/docs/plugins/hooks-reference#registerSiteRoutes) hook. It looks awesome, and would make accessing my special page that much easier for a front-end user!
  
  Here's how I implemented it in my `MyPluginPlugin.php` file:
  
  ```
  public function registerSiteRoutes()
  {
      return array(
          'myroute' => array('action' => 'myPlugin/myAction')
      );
  }
  
  ```
  
  **The good news is,** the route is properly followed, and my controller action gets loaded.
  
  **The bad news is,** suddenly the template that's supposed to be loaded can't be found. :(
  
  > **Template Error**
  >
  > Unable to find the template "myplugin/\_mytemplate".
  
  So does anyone know, **what's going on here?** I know that the `renderTemplate` method does some minor rewriting of the template path, but why would it be different when accessing via a front-end route?
  
  **Tags:** plugin-development, controller, routes
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2014-06-30. Score: 7 | Accepted answer
  
  Craft will only check for templates in your plugin’s templates/ folder during CP and action requests. When you start routing to your controller action via a site-facing route, it’s no longer either one of those; it’s just a normal Site request. So you will need to point Craft to your plugin’s templates folder explicitly.
  
  ```
  // Point Craft to this plugin's templates/ folder
  $templatesPath = craft()->path->getPluginsPath().'myplugin/templates/';
  craft()->path->setTemplatesPath($templatesPath);
  
  // Render and output the template
  $this->renderTemplate('_mytemplate', $variables);
  
  ```
  
  Note that it will no longer be necessary to include your plugin’s handle in the template path.
  
  > **Comments:**
  > **username_0**: Minor typo in your solution, it should apparently be `craft()->path->setTemplatesPath`... Other than that, it worked perfectly! Thanks username_1!  
  > **username_2**: Because I no longer need the plugin's handle in the template path, I also have to remove it from `extends` tags in the template. Which is fine, except when the layout I'm extending `extends` a layout from my main (non-plugin) templates. It now can't find that layout, because it's looking in my plugin templates.  
  > **username_1**: @username_2 Yeah if you go this route, you can only include templates that live inside the directory passed into setTemplatesPath(). No way around that currently.  
  
  ---
  
  