Answers.Body: <p>I think you're using Craft 2 syntax. This should work in Craft 3:</p>
  <pre><code>$vars = ['foo' =&gt; 'bar']; // variables loaded into the template
  $mode = 'cp'; // or &quot;site&quot;
  $html = Craft::$app-&gt;view-&gt;renderTemplate('path/to/template', $vars, $mode);
  return $html;
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-07-21T13:19:20.247Z
Answers.LastActivityDate: 2021-07-21T13:19:20.247Z
Answers.UserDisplayName: gioppe
Body: <p>I'm working on a plugin called <code>modelselector</code> and I want to use a template stored in the plugin <code>templates</code> folder but it should be shown on the front-end of the website.</p>
  
  <p>Currently the following direct URL works for me:
  <code>actions/modelSelector/showSelection/40c86a9b-53ec-43f4-8e8b-7c77ee0a13f5</code></p>
  
  <p>I also set up a site route like so:
  <code>'modelselector/(?P&lt;selectionUid&gt;[^\/]+)' =&gt; array('action' =&gt; 'modelSelector/showSelection')</code></p>
  
  <p>However when I go to: <code>modelselector/40c86a9b-53ec-43f4-8e8b-7c77ee0a13f5</code> I get the error: <code>Unable to find the template “modelselector/show”.</code>.</p>
  
  <p>I did some research and found that I need to set the template mode using: <code>craft()-&gt;templates-&gt;setTemplateMode(TemplateMode::CP);</code>. But this doesn't seem to work for me. It still can't find the template when the TemplateMode is on <code>CP</code> or <code>Site</code>.</p>
  
  <p>Any ideas?</p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2017-03-30T12:50:58.247Z
Comments.Text: Any help would be greatly appreciated!
Comments.UserDisplayName: Floriskoch
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2018-12-09T03:54:20.687Z
Comments.Text: Did you ever figure this out? I’m struggling with this too.
Comments.UserDisplayName: Chattervast
Tags: <plugin-development><templating>
Title: Using plugin template on front end
ThreadText: # Using plugin template on front end
  
  (Asked by: username_0 on 2017-03-27)
  
  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?
  
  **Tags:** plugin-development, templating
  
  > **Comments:**
  > **username_0**: Any help would be greatly appreciated!  
  > **username_1**: Did you ever figure this out? I’m struggling with this too.  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_2 on 2021-07-21. Score: 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;
  
  ```
  
  
  ---
  
  