Answers.Body: <p>Yes I was being dumb....</p>
  <p>I wasn't returning the rendered template. Controller should be</p>
  <pre><code>public function actionLoadHolidays()
      {
          $request = Craft::$app-&gt;request;
          $destination = $request-&gt;post('destination');
          
          $holidays = [];
          
          $oldMode = Craft::$app-&gt;view-&gt;getTemplateMode();
          Craft::$app-&gt;getView()-&gt;setTemplateMode(View::TEMPLATE_MODE_SITE);
      
          return $this-&gt;renderTemplate('how-to-book/holidays-for-destination-options.twig', array(
              'destination' =&gt; $destination,
              'holidays' =&gt; $holidays
          ));
  
      }
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-08-19T10:14:21.993Z
Answers.LastActivityDate: 2020-08-19T10:14:21.993Z
Answers.UserDisplayName: foamcow
Body: <p>Once again going out of my mind trying to figure something out...
  I have a custom controller which I want to return a rendered template. The template should, ideally, reside in my front end templates directory.</p>
  <p>But I can't for the life of me figure out the path to use.
  The template I want is at <code>./templates/how-to-book/holidays-for-destination-options.twig</code> but my controller is unable to find it seemingly regardless of how I try to write the path.</p>
  <p>This is a sketchy version of the controller (I'm not getting any data yet, just want to render the correct template)</p>
  <pre><code>public function actionLoadHolidays()
      {
          $request = Craft::$app-&gt;request;
          $destination = $request-&gt;post('destination');
          
          $holidays = [];
          
          $oldMode = Craft::$app-&gt;view-&gt;getTemplateMode();
          Craft::$app-&gt;getView()-&gt;setTemplateMode(View::TEMPLATE_MODE_SITE);
      
          $this-&gt;renderTemplate('how-to-book/holidays-for-destination-options.twig', array(
              'destination' =&gt; $destination,
              'holidays' =&gt; $holidays
          ));
          Craft::$app-&gt;view-&gt;setTemplateMode($oldMode);
  
      }
  </code></pre>
  <p>Using the path as shown, I get the response <code>Not Found: Template not found: actions/my-module/holidays/load-holidays</code></p>
  <p>I'm hitting this controller via an Ajax request if that has any bearing.</p>
  <p>Can someone please help me figure this out - I'm feeling dumb!</p>
  
Tags: <plugin-development><craft3><controller><modules>
Title: Rendering a template from a controller - unable to find template
ThreadText: # Rendering a template from a controller - unable to find template
  
  (Asked by: username_0 on 2020-08-19)
  
  Once again going out of my mind trying to figure something out...
  I have a custom controller which I want to return a rendered template. The template should, ideally, reside in my front end templates directory.
  
  But I can't for the life of me figure out the path to use.
  The template I want is at `./templates/how-to-book/holidays-for-destination-options.twig` but my controller is unable to find it seemingly regardless of how I try to write the path.
  
  This is a sketchy version of the controller (I'm not getting any data yet, just want to render the correct template)
  
  ```
  public function actionLoadHolidays()
      {
          $request = Craft::$app->request;
          $destination = $request->post('destination');
          
          $holidays = [];
          
          $oldMode = Craft::$app->view->getTemplateMode();
          Craft::$app->getView()->setTemplateMode(View::TEMPLATE_MODE_SITE);
      
          $this->renderTemplate('how-to-book/holidays-for-destination-options.twig', array(
              'destination' => $destination,
              'holidays' => $holidays
          ));
          Craft::$app->view->setTemplateMode($oldMode);
  
      }
  
  ```
  
  Using the path as shown, I get the response `Not Found: Template not found: actions/my-module/holidays/load-holidays`
  
  I'm hitting this controller via an Ajax request if that has any bearing.
  
  Can someone please help me figure this out - I'm feeling dumb!
  
  **Tags:** plugin-development, craft3, controller, modules
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_0 on 2020-08-19. Score: 2 | Accepted answer
  
  Yes I was being dumb....
  
  I wasn't returning the rendered template. Controller should be
  
  ```
  public function actionLoadHolidays()
      {
          $request = Craft::$app->request;
          $destination = $request->post('destination');
          
          $holidays = [];
          
          $oldMode = Craft::$app->view->getTemplateMode();
          Craft::$app->getView()->setTemplateMode(View::TEMPLATE_MODE_SITE);
      
          return $this->renderTemplate('how-to-book/holidays-for-destination-options.twig', array(
              'destination' => $destination,
              'holidays' => $holidays
          ));
  
      }
  
  ```
  
  
  ---
  
  