4

I'm working on a plugin called modelselector and I want to use a template stored in the plugin templates folder but it should be shown on the front-end of the website.

Currently the following direct URL works for me: actions/modelSelector/showSelection/40c86a9b-53ec-43f4-8e8b-7c77ee0a13f5

I also set up a site route like so: 'modelselector/(?P<selectionUid>[^\/]+)' => array('action' => 'modelSelector/showSelection')

However when I go to: modelselector/40c86a9b-53ec-43f4-8e8b-7c77ee0a13f5 I get the error: Unable to find the template “modelselector/show”..

I did some research and found that I need to set the template mode using: craft()->templates->setTemplateMode(TemplateMode::CP);. But this doesn't seem to work for me. It still can't find the template when the TemplateMode is on CP or Site.

Any ideas?

2
  • 1
    Any help would be greatly appreciated!
    – Floriskoch
    Mar 30 '17 at 12:50
  • Did you ever figure this out? I’m struggling with this too. Dec 9 '18 at 3:54
1

I think you're using Craft 2 syntax. This should work in Craft 3:

$vars = ['foo' => 'bar']; // variables loaded into the template
$mode = 'cp'; // or "site"
$html = Craft::$app->view->renderTemplate('path/to/template', $vars, $mode);
return $html;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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