Answers.Body: <p>Just added this note to the <a href="http://buildwithcraft.com/docs/plugins/templates" rel="noreferrer">Plugin Templates</a> documentation, which should answer your question:</p>
  
  
  
  <blockquote>
    <p>Craft will only automatically look for templates within the plugin folders for CP requests. If you are going to be calling TemplatesService::render() from a front end site request, you will need to manually tell Craft where to find your template using <a href="http://buildwithcraft.com/docs/apis/pathservice#setTemplatesPath" rel="noreferrer">PathService::setTemplatesPath()</a> first:</p>
  
  <pre class="lang-php prettyprint-override"><code>$oldPath = craft()-&gt;path-&gt;getTemplatesPath();
  $newPath = craft()-&gt;path-&gt;getPluginsPath().'pluginHandle/templates';
  craft()-&gt;path-&gt;setTemplatesPath($newPath)
  $html = craft()-&gt;templates-&gt;render('path/to/template');
  craft()-&gt;path-&gt;setTemplatesPath($oldPath);
  </code></pre>
    
    <p>If you do this, you won’t be needing to begin the template path with your plugin handle.</p>
  </blockquote>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-08-15T14:24:07.623Z
Answers.Text: Thanks, Brandon. I still couldn't get this code to work (`Unable to find the template “_headers”.`), and its a lot of code for what we're trying to accomplish, so I just included the entire template in the `Variable` as a string and used `return craft()->templates->renderString($headerTemplateString);` instead.
Answers.UserDisplayName: cmal
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-08-15T03:32:44.170Z
Answers.LastActivityDate: 2014-08-15T03:32:44.170Z
Answers.UserDisplayName: Brandon Kelly
Body: <p>I'm new to Craft template development and one of the first things I'm trying to do is create a <code>Variable</code> that renders a template into the template its called from.</p>
  
  <p>My directory structure looks like this:</p>
  
  <pre><code>/craft
    /plugins
      /test
        /templates
          _headers.html
        /variables
          TestVariable.php
  </code></pre>
  
  <p>Here is the Variable:</p>
  
  <pre><code>&lt;?php
  
  namespace Craft;
  
  class TestVariable
  {
      /**
       * Get header for test code
       *
       * @return string
       */
      public function headers()
      {
          return craft()-&gt;templates-&gt;render('test/_headers');
      }
  }
  </code></pre>
  
  <p>And I'm calling it in the template with a simple: <code>{{ craft.test.headers }}</code></p>
  
  <p>My template is erroring with <code>Unable to find the template “test/_headers”.</code></p>
  
  <p>What am I misunderstanding here?</p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2014-08-14T18:50:17.873Z
Comments.Text: I ran into this issue yesterday, and I too am unsure of the answer. What I did find out is that when you try to render templates from the front-end, it looks to the front-end /templates directory for the Craft install, not the directory for your plugin. If there is a way to render templates from the plugin directory, I too would like to know. But looking through the code for a bit, I couldn't find a way to do it.
Comments.UserDisplayName: Justin Kimbrell
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2014-08-14T22:01:08.363Z
Comments.Text: http://buildwithcraft.com/docs/plugins/templates is very unclear about where `craft()->templates->render('test/_headers');` can be called from for plugins. It can definitely be called from the base plugin PHP, but beyond that I don't know.
Comments.UserDisplayName: cmal
Tags: <plugin-development>
Title: Plugin Variable can't find template
ThreadText: # Plugin Variable can't find template
  
  (Asked by: username_0 on 2014-08-14)
  
  I'm new to Craft template development and one of the first things I'm trying to do is create a `Variable` that renders a template into the template its called from.
  
  My directory structure looks like this:
  
  ```
  /craft
    /plugins
      /test
        /templates
          _headers.html
        /variables
          TestVariable.php
  
  ```
  
  Here is the Variable:
  
  ```
  <?php
  
  namespace Craft;
  
  class TestVariable
  {
      /**
       * Get header for test code
       *
       * @return string
       */
      public function headers()
      {
          return craft()->templates->render('test/_headers');
      }
  }
  
  ```
  
  And I'm calling it in the template with a simple: `{{ craft.test.headers }}`
  
  My template is erroring with `Unable to find the template “test/_headers”.`
  
  What am I misunderstanding here?
  
  **Tags:** plugin-development
  
  > **Comments:**
  > **username_1**: I ran into this issue yesterday, and I too am unsure of the answer. What I did find out is that when you try to render templates from the front-end, it looks to the front-end /templates directory for the Craft install, not the directory for your plugin. If there is a way to render templates from the plugin directory, I too would like to know. But looking through the code for a bit, I couldn't find a way to do it.  
  > **username_0**: http://buildwithcraft.com/docs/plugins/templates is very unclear about where `craft()->templates->render('test/_headers');` can be called from for plugins. It can definitely be called from the base plugin PHP, but beyond that I don't know.  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_2 on 2014-08-15. Score: 5
  
  Just added this note to the [Plugin Templates](http://buildwithcraft.com/docs/plugins/templates) documentation, which should answer your question:
  
  > Craft will only automatically look for templates within the plugin folders for CP requests. If you are going to be calling TemplatesService::render() from a front end site request, you will need to manually tell Craft where to find your template using [PathService::setTemplatesPath()](http://buildwithcraft.com/docs/apis/pathservice#setTemplatesPath) first:
  >
  > ```php
  > $oldPath = craft()->path->getTemplatesPath();
  > $newPath = craft()->path->getPluginsPath().'pluginHandle/templates';
  > craft()->path->setTemplatesPath($newPath)
  > $html = craft()->templates->render('path/to/template');
  > craft()->path->setTemplatesPath($oldPath);
  >
  > ```
  >
  > If you do this, you won’t be needing to begin the template path with your plugin handle.
  
  > **Comments:**
  > **username_0**: Thanks, username_2. I still couldn't get this code to work (`Unable to find the template “_headers”.`), and its a lot of code for what we're trying to accomplish, so I just included the entire template in the `Variable` as a string and used `return craft()->templates->renderString($headerTemplateString);` instead.  
  
  ---
  
  