3

I'm trying to access a CP template from the frontend, and i'm doing something like this in my plugin:

<?php

...
$oldMode  = craft()->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.

1
  • Did you figure this out? I have the same problem..
    – Floriskoch
    Commented Mar 27, 2017 at 10:24

1 Answer 1

-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...

2
  • 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: craftcms.stackexchange.com/questions/14375/… Commented Aug 22, 2016 at 10:47
  • 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. Commented Aug 24, 2016 at 0:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.