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.

Fred Carlsen
  • 2,997
  • 13
  • 23

1 Answers1

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

narration_sd
  • 1,707
  • 10
  • 23
  • 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 Aug 22 '16 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.

    – narration_sd Aug 24 '16 at 00:52