Answers.Body: <p>I haven't tried calling a template from a controller, so I may not be any help but I've used</p>
  
  <pre><code>...-&gt;render(...)
  </code></pre>
  
  <p>in my main plugin Class like this:</p>
  
  <p><strong>MyPlugin.php</strong></p>
  
  <pre><code>return craft()-&gt;templates-&gt;render('myplugin/_settings', array('settings' =&gt; $this-&gt;getSettings()));
  </code></pre>
  
  <p>Maybe the render method is looking for another argument?</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>Oh wait... I was wrong, it looks like I do...</p>
  
  <p><strong>MyPluginController.php</strong></p>
  
  <pre><code>$vars['users'] = craft()-&gt;user-&gt;listUsers();
  $this-&gt;renderTemplate('myplugin/index', $vars);
  </code></pre>
  
  <p>Then I have a variables file:</p>
  
  <p><strong>MyPluginVariable.php</strong></p>
  
  <pre><code>public function getContacts()
  {
      return craft()-&gt;contactForm-&gt;getUsers();
  }
  </code></pre>
  
  <p>Which ties back to the my service:</p>
  
  <p><strong>MyPluginService.php</strong></p>
  
  <pre><code>public function getUsers()
  {
      return MyPluginRecord::model()-&gt;findAll(array('order' =&gt; 'dateCreated desc'));
  }
  </code></pre>
  
  <p>Maybe that will help get you rolling?</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-08-13T10:17:19.697Z
Answers.Text: cheers that has helped somewhat. How are you accessing the variable object in the template so you can use the variables?
Answers.UserDisplayName: Lettie
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-08-13T10:24:43.447Z
Answers.Text: Ignore last comment I've worked it out. Just had to make couple of changes to my service. Thanks for the help.
Answers.UserDisplayName: Lettie
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-08-13T13:06:48.963Z
Answers.Text: Awesome! Glad it helped.
Answers.UserDisplayName: Damon
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-08-12T19:38:08.313Z
Answers.LastActivityDate: 2015-08-12T21:55:28.327Z
Answers.LastEditDate: 2015-08-12T21:55:28.327Z
Answers.UserDisplayName: Damon
Body: <p>I have an issue with rendering a template from within my controller in my plugin. It just seems to re-direct to the dashboard instead of bringing up the template.</p>
  
  <p>I have a widget on the dashboard that calls an action in my plugin's controller file. This works as I can print_r the object I am creating. However when it gets to the render code it just keeps re-directing back to the dashboard. I've even tried stripping out all the code apart from the render call and it still does it. The code making the call is:</p>
  
  <pre><code>return craft()-&gt;templates-&gt;render('pluginName/index.html');
  </code></pre>
  
  <p>Which is currently the only code in the plugin function. The plugin has a templates folder where the index.html is held. I've also stripped the template down so it only contains the following:</p>
  
  <pre><code>{% extends "_layouts/cp" %}
  {% set centered = true %}
  {% set title = "The Title"|t %}
  
  {% set content %}
  
  &lt;p&gt;List the users&lt;/p&gt;
  
  {% endset %}
  </code></pre>
  
  <p>Any clues anyone. </p>
  
Tags: <plugin-development><templating><plugins>
Title: Issue with rendering a template from a plugin function
ThreadText: # Issue with rendering a template from a plugin function
  
  (Asked by: username_0 on 2015-08-12)
  
  I have an issue with rendering a template from within my controller in my plugin. It just seems to re-direct to the dashboard instead of bringing up the template.
  
  I have a widget on the dashboard that calls an action in my plugin's controller file. This works as I can print\_r the object I am creating. However when it gets to the render code it just keeps re-directing back to the dashboard. I've even tried stripping out all the code apart from the render call and it still does it. The code making the call is:
  
  ```
  return craft()->templates->render('pluginName/index.html');
  
  ```
  
  Which is currently the only code in the plugin function. The plugin has a templates folder where the index.html is held. I've also stripped the template down so it only contains the following:
  
  ```
  {% extends "_layouts/cp" %}
  {% set centered = true %}
  {% set title = "The Title"|t %}
  
  {% set content %}
  
  <p>List the users</p>
  
  {% endset %}
  
  ```
  
  Any clues anyone.
  
  **Tags:** plugin-development, templating, plugins
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2015-08-12. Score: 6
  
  I haven't tried calling a template from a controller, so I may not be any help but I've used
  
  ```
  ...->render(...)
  
  ```
  
  in my main plugin Class like this:
  
  **MyPlugin.php**
  
  ```
  return craft()->templates->render('myplugin/_settings', array('settings' => $this->getSettings()));
  
  ```
  
  Maybe the render method is looking for another argument?
  
  **EDIT**
  
  Oh wait... I was wrong, it looks like I do...
  
  **MyPluginController.php**
  
  ```
  $vars['users'] = craft()->user->listUsers();
  $this->renderTemplate('myplugin/index', $vars);
  
  ```
  
  Then I have a variables file:
  
  **MyPluginVariable.php**
  
  ```
  public function getContacts()
  {
      return craft()->contactForm->getUsers();
  }
  
  ```
  
  Which ties back to the my service:
  
  **MyPluginService.php**
  
  ```
  public function getUsers()
  {
      return MyPluginRecord::model()->findAll(array('order' => 'dateCreated desc'));
  }
  
  ```
  
  Maybe that will help get you rolling?
  
  > **Comments:**
  > **username_0**: cheers that has helped somewhat. How are you accessing the variable object in the template so you can use the variables?  
  > **username_0**: Ignore last comment I've worked it out. Just had to make couple of changes to my service. Thanks for the help.  
  > **username_1**: Awesome! Glad it helped.  
  
  ---
  
  