<p>May have answered on Stack/plugindev: </p>

<p>@sjelfull  was intrigued, so started reading code about this, until the thought occurred: you seem to be asking a front end instance to access a CP template? This shouldn't be allowed unless it was a CP or action request, no?  The setting to TemplateMode can't fail this way, must be in trying to use the template, and that may fall apart at line 904 of TemplateService.php, would think. I don't put it past you to have another clever idea, though :wink: -- Takk for de...</p>

CC BY-SA 3.0
2016-08-22T10:47:29.643Z
It should be allowed, because it's a plugin method that is being run from the frontend. I've done this before with the setTemplatePath() method, but Brandon Kelly posted this example here: http://craftcms.stackexchange.com/questions/14375/how-do-i-fix-gettemplatespath-settemplatespath-deprecation-errors/14376#14376
Fred Carlsen
CC BY-SA 3.0
2016-08-24T00:52:35.373Z
Yes, I think you're right, Fred. Per Slack, I had part of his discussion here backwards, and you should be able to do this.

Thus, a bug, and maybe that line 904 is the root of that, something unintended having happened.
narration_sd
CC BY-SA 3.0
2016-08-20T20:29:53.347Z
2016-08-20T20:29:53.347Z
narration_sd
<p>I'm trying to access a CP template from the frontend, and i'm doing something like this in my plugin:</p>

<pre><code>&lt;?php

...
$oldMode  = craft()-&gt;templates-&gt;getTemplateMode();
craft()-&gt;templates-&gt;setTemplateMode(TemplateMode::CP);

$widget = craft()-&gt;templates-&gt;render('plugin/Plugin_Template', array(
    'chatraID' =&gt; $chatraID,
));

craft()-&gt;templates-&gt;setTemplateMode($oldMode);
...
</code></pre>

<p>I'm getting the <em>Unable to find the template</em> error, though. I have verified that the plugin is installed, and that the template  <em>plugin/Plugin_Template</em> is accessible from the CP.</p>

CC BY-SA 3.0
2017-03-27T10:24:18.317Z
Did you figure this out? I have the same problem..
Floriskoch
<plugin-development><templating>
Using setTemplateMode on the frontend
# Using setTemplateMode on the frontend

(Asked by: username_0 on 2016-08-20)

I'm trying to access a CP template from the frontend, and i'm doing something like this in my plugin:
templates->getTemplateMode();
craft()->templates->setTemplateMode(TemplateMode::CP);

$widget = craft()->templates->render('plugin/Plugin_Template', array(
    'chatraID' => $chatraID,
));

craft()->templates->setTemplateMode($oldMode);
...

I'm getting the Unable to find the template error, though. I have verified that the plugin is installed, and that the template  plugin/Plugin_Template is accessible from the CP.

**Tags:** plugin-development, templating
> **Comments:**
> **username_1**: Did you figure this out? I have the same problem..  

---

## 1 answers

### Answer by username_2 on 2016-08-20. Score: -1

May have answered on Stack/plugindev:

@sjelfull was intrigued, so started reading code about this, until the thought occurred: you seem to be asking a front end instance to access a CP template? This shouldn't be allowed unless it was a CP or action request, no? The setting to TemplateMode can't fail this way, must be in trying to use the template, and that may fall apart at line 904 of TemplateService.php, would think. I don't put it past you to have another clever idea, though :wink: -- Takk for de...

> **Comments:**
> **username_0**: It should be allowed, because it's a plugin method that is being run from the frontend. I've done this before with the setTemplatePath() method, but Brandon Kelly posted this example here: http://craftcms.stackexchange.com/questions/14375/how-do-i-fix-gettemplatespath-settemplatespath-deprecation-errors/14376#14376  
> **username_2**: Yes, I think you're right, Fred. Per Slack, I had part of his discussion here backwards, and you should be able to do this.  Thus, a bug, and maybe that line 904 is the root of that, something unintended having happened.  

---

