Answers.Body: <p>There’s no reason for your controller to return anything – it will never be checked.</p>
  
  <p>Many requests call more than one controller action, so it would be pretty presumptuous for Craft to think that it should actually output whatever your controller returns, and end the request.</p>
  
  <p>Instead, it’s up to the actual controller to do the outputting, and end the request, if that’s what it wants to do.</p>
  
  <p><code>$this-&gt;renderTemplate()</code> comes from BaseController, and it’s basically a wrapper for <code>craft()-&gt;templates-&gt;render()</code>, except that after calling that, it will also set the Content-Type header for the request, insert any queued-up JS and CSS, and then end the request.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-06-26T06:37:10.280Z
Answers.Text: Brandon wins! I'll send you a free copy of my book, when I eventually write it. ;)
Answers.UserDisplayName: Lindsey D
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-06-26T05:46:50.203Z
Answers.LastActivityDate: 2014-06-26T05:46:50.203Z
Answers.UserDisplayName: Brandon Kelly
Body: <p>When developing a plugin, I am registering routes to controller actions. Other frameworks, read that as Laravel, typically return the controllers response.</p>
  
  <pre><code>public function showProfile($id)
  {
      $user = User::find($id);
  
      return View::make('user.profile', array('user' =&gt; $user));
  }
  </code></pre>
  
  <p>However, in Craft to render a template from your controller you would use the following.</p>
  
  <pre><code>public function actionPluginIndex()
  {
     $this-&gt;renderTemplate('pluginName/template');
  }
  </code></pre>
  
  <p>At the same time, you can also return the rendered template this way and it functions as expected.</p>
  
  <pre><code>public function actionPluginIndex()
  {
     return $this-&gt;renderTemplate('pluginName/template);
  }
  </code></pre>
  
  <p>Looking at <code>craft/app/controllers/BaseController.php</code> templateRender method shows that it accepts a parameter <code>return</code>.</p>
  
  <p>So the real question is <code>to return or not to return</code> and I was hoping for a more technical explanation on the way Craft handles this.</p>
  
Tags: <plugin-development><plugins><controller><best-practice>
Title: Should my controllers actions 'return' when rendering templates?
ThreadText: # Should my controllers actions 'return' when rendering templates?
  
  (Asked by: username_0 on 2014-06-25)
  
  When developing a plugin, I am registering routes to controller actions. Other frameworks, read that as Laravel, typically return the controllers response.
  
  ```
  public function showProfile($id)
  {
      $user = User::find($id);
  
      return View::make('user.profile', array('user' => $user));
  }
  
  ```
  
  However, in Craft to render a template from your controller you would use the following.
  
  ```
  public function actionPluginIndex()
  {
     $this->renderTemplate('pluginName/template');
  }
  
  ```
  
  At the same time, you can also return the rendered template this way and it functions as expected.
  
  ```
  public function actionPluginIndex()
  {
     return $this->renderTemplate('pluginName/template);
  }
  
  ```
  
  Looking at `craft/app/controllers/BaseController.php` templateRender method shows that it accepts a parameter `return`.
  
  So the real question is `to return or not to return` and I was hoping for a more technical explanation on the way Craft handles this.
  
  **Tags:** plugin-development, plugins, controller, best-practice
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2014-06-26. Score: 5 | Accepted answer
  
  There’s no reason for your controller to return anything – it will never be checked.
  
  Many requests call more than one controller action, so it would be pretty presumptuous for Craft to think that it should actually output whatever your controller returns, and end the request.
  
  Instead, it’s up to the actual controller to do the outputting, and end the request, if that’s what it wants to do.
  
  `$this->renderTemplate()` comes from BaseController, and it’s basically a wrapper for `craft()->templates->render()`, except that after calling that, it will also set the Content-Type header for the request, insert any queued-up JS and CSS, and then end the request.
  
  > **Comments:**
  > **username_2**: username_1 wins! I'll send you a free copy of my book, when I eventually write it. ;)  
  
  ---
  
  