Answers.Body: <p>Craft will only serve templates from craft/templates/ by default if it’s a front-end site request.</p>
  
  <p>To explicitly tell Craft to serve templates from there, you can use <a href="http://buildwithcraft.com/classreference/services/PathService#setTemplatesPath-detail" rel="noreferrer">PathService::setTemplatesPath()</a>:</p>
  
  <pre class="lang-php prettyprint-override"><code>$path = craft()-&gt;path-&gt;getSiteTemplatesPath();
  craft()-&gt;path-&gt;setTemplatesPath($path);
  
  $this-&gt;renderTemplate('path/to/template', $variables);
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-10-28T09:41:18.650Z
Answers.LastActivityDate: 2015-06-15T17:43:38.180Z
Answers.LastEditDate: 2015-06-15T17:43:38.180Z
Answers.UserDisplayName: Brandon Kelly
Body: <p>I want to be able to render a template in the main 'templates' directory from within a plugin controller.</p>
  
  <p>Basically the controller gets the url request, does some work and then renders a template saved in the 'craft/templates' directory instead of the 'plugin/templates' directory.</p>
  
  <p>I have tried the plugin path trick mentioned on this page <a href="https://craftcms.com/docs/plugins/templates" rel="nofollow noreferrer">https://craftcms.com/docs/plugins/templates</a> without any success.</p>
  
  <p>Any ideas?</p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2014-10-24T22:15:05.447Z
Comments.Text: The trick on that page should do it for you. Can you `var_dump` the paths to make sure they are pointing to where you think they are pointing?
Comments.UserDisplayName: Brad Bell
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2014-10-24T23:22:26.880Z
Comments.Text: The path echoes out where I would expect '/Users/derrick/Documents/wwwroot/iha/craft/templates/' however when I do $html = craft()->templates->render('test'); it always get a 404 page not found. I don't need an entry or route setup to the 'test' template correct? If I browser to local.site.com/test I see the test template.
Comments.UserDisplayName: Derrick Grigg
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2014-10-25T16:57:18.990Z
Comments.Text: Digging a little more into this. If I pass a path for a template that doesn't exist I get an error message "Unable to find the template “_test”." However if pass a path for a template that does exist, I don't get that error message but I do get redirected to the 404, page not found. Does that make sense? Right now the template has no logic in just a little markup, there's nothing in it to redirect. Is there something that needs to get returned from the controller method to prevent a 404?
Comments.UserDisplayName: Derrick Grigg
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2014-10-25T16:59:22.027Z
Comments.Text: Found the answer, you need to use the $this->renderTemplate() in the controller vs the craft()->templates->render();
Comments.UserDisplayName: Derrick Grigg
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2014-10-28T09:43:08.393Z
Comments.Text: @DerrickGrigg [BaseController::renderTemplate()](http://buildwithcraft.com/classreference/controllers/BaseController#renderTemplate-detail) calls [TemplatesService::render()](http://buildwithcraft.com/classreference/services/TemplatesService#render-detail) internally. Guessing that you just happened to be triggering Craft from a site request when testing that theory. See my answer below.
Comments.UserDisplayName: Brandon Kelly
Tags: <plugin-development><templating>
Title: renderTemplate in a plugin for front end request using front end template
ThreadText: # renderTemplate in a plugin for front end request using front end template
  
  (Asked by: username_0 on 2014-10-24)
  
  I want to be able to render a template in the main 'templates' directory from within a plugin controller.
  
  Basically the controller gets the url request, does some work and then renders a template saved in the 'craft/templates' directory instead of the 'plugin/templates' directory.
  
  I have tried the plugin path trick mentioned on this page <https://craftcms.com/docs/plugins/templates> without any success.
  
  Any ideas?
  
  **Tags:** plugin-development, templating
  
  > **Comments:**
  > **username_1**: The trick on that page should do it for you. Can you `var_dump` the paths to make sure they are pointing to where you think they are pointing?  
  > **username_0**: The path echoes out where I would expect '/Users/username_0/Documents/wwwroot/iha/craft/templates/' however when I do $html = craft()->templates->render('test'); it always get a 404 page not found. I don't need an entry or route setup to the 'test' template correct? If I browser to local.site.com/test I see the test template.  
  > **username_0**: Digging a little more into this. If I pass a path for a template that doesn't exist I get an error message "Unable to find the template “_test”." However if pass a path for a template that does exist, I don't get that error message but I do get redirected to the 404, page not found. Does that make sense? Right now the template has no logic in just a little markup, there's nothing in it to redirect. Is there something that needs to get returned from the controller method to prevent a 404?  
  > **username_0**: Found the answer, you need to use the $this->renderTemplate() in the controller vs the craft()->templates->render();  
  > **username_2**: @username_0 [BaseController::renderTemplate()](http://buildwithcraft.com/classreference/controllers/BaseController#renderTemplate-detail) calls [TemplatesService::render()](http://buildwithcraft.com/classreference/services/TemplatesService#render-detail) internally. Guessing that you just happened to be triggering Craft from a site request when testing that theory. See my answer below.  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_2 on 2014-10-28. Score: 8
  
  Craft will only serve templates from craft/templates/ by default if it’s a front-end site request.
  
  To explicitly tell Craft to serve templates from there, you can use [PathService::setTemplatesPath()](http://buildwithcraft.com/classreference/services/PathService#setTemplatesPath-detail):
  
  ```php
  $path = craft()->path->getSiteTemplatesPath();
  craft()->path->setTemplatesPath($path);
  
  $this->renderTemplate('path/to/template', $variables);
  
  ```
  
  
  ---
  
  