Answers.Body: <p>Now working. Turned out to be user error on my part. I had neglected the alias that I had created so the path to the template directory was incorrect. </p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-11-12T15:47:22.950Z
Answers.Text: Could you share example code that actually worked for you? Thanks!
Answers.UserDisplayName: Gary Reckard
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-11-15T10:18:53.470Z
Answers.Text: Hi Gary, this is now a legacy project and the code has been archived. Unfortunately I do not have access too it any more, sorry,
Answers.UserDisplayName: jaypratt
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-07-15T15:36:55.197Z
Answers.LastActivityDate: 2019-07-15T15:36:55.197Z
Answers.UserDisplayName: jaypratt
Body: <p>I have been searching around SE and the web in general for an answer to this. There seems to be plenty of solutions but none appear to be working for me.</p>
  
  <p>I have a simple module that has a variable that gets called from a twig template in order to render a form.</p>
  
  <p>The problem is no matter what I do I cannot get the module to render the HTML from within its own <code>/templates</code> directory.</p>
  
  <p>The variable code is: </p>
  
  <pre><code>$oldMode = \Craft::$app-&gt;view-&gt;getTemplateMode();
  \Craft::$app-&gt;view-&gt;setTemplateMode(View::TEMPLATE_MODE_SITE);
  $html = \Craft::$app-&gt;view-&gt;renderTemplate('../templates/_journey-planner.html');
  \Craft::$app-&gt;view-&gt;setTemplateMode($oldMode);
  return $html;
  </code></pre>
  
  <p>This is taken from the Craft docs. I have also used:</p>
  
  <pre><code>Event::on(View::class,
            View::EVENT_REGISTER_SITE_TEMPLATE_ROOTS,
            function (RegisterTemplateRootsEvent $e) {
                  $e-&gt;roots['journeyplannermodule'] = 'journeyplannermodule/src/templates';
              }
          );
  </code></pre>
  
  <p>Within the module's <code>init()</code> function (not sure if this is actually required or not).</p>
  
  <p>What am I doing wrong and what do I need to do to simply display this template within the twig template? </p>
  
  <p>I am calling the variable method with:
  <code>{{ craft.journeyPlannerModule.getJourneyPlanner }}</code> </p>
  
  <p>Craft Version: 3.2.0</p>
  
Tags: <templating><modules>
Title: Render template from Module in twig template
ThreadText: # Render template from Module in twig template
  
  (Asked by: username_0 on 2019-07-15)
  
  I have been searching around SE and the web in general for an answer to this. There seems to be plenty of solutions but none appear to be working for me.
  
  I have a simple module that has a variable that gets called from a twig template in order to render a form.
  
  The problem is no matter what I do I cannot get the module to render the HTML from within its own `/templates` directory.
  
  The variable code is:
  
  ```
  $oldMode = \Craft::$app->view->getTemplateMode();
  \Craft::$app->view->setTemplateMode(View::TEMPLATE_MODE_SITE);
  $html = \Craft::$app->view->renderTemplate('../templates/_journey-planner.html');
  \Craft::$app->view->setTemplateMode($oldMode);
  return $html;
  
  ```
  
  This is taken from the Craft docs. I have also used:
  
  ```
  Event::on(View::class,
            View::EVENT_REGISTER_SITE_TEMPLATE_ROOTS,
            function (RegisterTemplateRootsEvent $e) {
                  $e->roots['journeyplannermodule'] = 'journeyplannermodule/src/templates';
              }
          );
  
  ```
  
  Within the module's `init()` function (not sure if this is actually required or not).
  
  What am I doing wrong and what do I need to do to simply display this template within the twig template?
  
  I am calling the variable method with:
  `{{ craft.journeyPlannerModule.getJourneyPlanner }}`
  
  Craft Version: 3.2.0
  
  **Tags:** templating, modules
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_0 on 2019-07-15. Score: 1 | Accepted answer
  
  Now working. Turned out to be user error on my part. I had neglected the alias that I had created so the path to the template directory was incorrect.
  
  > **Comments:**
  > **username_1**: Could you share example code that actually worked for you? Thanks!  
  > **username_0**: Hi username_1, this is now a legacy project and the code has been archived. Unfortunately I do not have access too it any more, sorry,  
  
  ---
  
  