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?

Brad Bell
  • 67,440
  • 6
  • 73
  • 143
Floriskoch
  • 349
  • 1
  • 6

1 Answers1

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;
gioppe
  • 414
  • 2
  • 9