Body: <p>I'm trying to render a template from a console command, but i'm getting the following error:</p>
  
  <pre><code>Craft\ConsoleApp and its behaviors do not have a method or closure named "getTheme"
  </code></pre>
  
  <p>The code looks like this:</p>
  
  <pre><code>public function actionIndexTemplate ($id = null)
  {
      $criteria          = craft()-&gt;elements-&gt;getCriteria(ElementType::Entry);
      $criteria-&gt;section = 'products';
      $criteria-&gt;limit   = 1;
      $criteria-&gt;id      = $id;
      $entry             = $criteria-&gt;first();
  
      if ( $entry ) {
          $output = craft()-&gt;templates-&gt;render('indexer/Product', [
              'element' =&gt; $entry
          ]);
          $data       = json_decode($output, $assoc = true);
      }
      else {
          echo "No entry found\n";
      }
  }
  </code></pre>
  
  <p>And here is the stack trace:</p>
  
  <pre><code>CException: Craft\ConsoleApp and its behaviors do not have a method or closure named "getTheme". in /craft/app/framework/base/CComponent.php:266
  Stack trace:
  #0 /craft/app/framework/base/CErrorHandler.php(390): CComponent-&gt;__call('getTheme', Array)
  #1 /craft/app/framework/base/CErrorHandler.php(340): CErrorHandler-&gt;getViewFile('exception', 500)
  #2 /craft/app/etc/errors/ErrorHandler.php(233): CErrorHandler-&gt;render('exception', Array)
  #3 /craft/app/etc/errors/ErrorHandler.php(137): Craft\ErrorHandler-&gt;handleTwigError(Object(Craft\TemplateLoaderException))
  #4 /craft/app/framework/base/CErrorHandler.php(131): Craft\ErrorHandler-&gt;handleException(Object(Craft\TemplateLoaderException))
  #5 /craft/app/framework/base/CApplication.php(750): CErrorHandler-&gt;handle(Object(CExceptionEvent))
  #6 [internal function]: CApplication-&gt;handleException(Object(Craft\TemplateLoaderException))
  #7 {main}%
  </code></pre>
  
  <p>Here is the underlying error:</p>
  
  <pre><code>2016/11/23 18:15:13 [error] [exception.Craft\TemplateLoaderException] Craft\TemplateLoaderException: Ikke i stand til å finne malen “indexer/Product”. in /craft/app/etc/templating/twigextensions/TemplateLoader.php:123
  Stack trace:
  #0 /craft/app/etc/templating/twigextensions/TemplateLoader.php(71): Craft\TemplateLoader-&gt;_findTemplate('indexer/P...')
  #1 /craft/app/vendor/twig/twig/lib/Twig/Environment.php(312): Craft\TemplateLoader-&gt;getCacheKey('indexer/P...')
  #2 /craft/app/vendor/twig/twig/lib/Twig/Environment.php(378): Twig_Environment-&gt;getTemplateClass('indexer/P...', NULL)
  #3 /craft/app/etc/templating/TwigEnvironment.php(61): Twig_Environment-&gt;loadTemplate('indexer/P...', NULL)
  #4 /craft/app/vendor/twig/twig/lib/Twig/Environment.php(347): Craft\TwigEnvironment-&gt;loadTemplate('indexer/P...')
  #5 /craft/app/services/TemplatesService.php(253): Twig_Environment-&gt;render('indexer/P...', Array)
  #6 /craft/plugins/indexer/services/Indexer_IndexService.php(136): Craft\TemplatesService-&gt;render('indexer/P...', Array)
  #7 /craft/plugins/indexer/consolecommands/IndexerCommand.php(93): Craft\Indexer_IndexService-&gt;renderTemplate(Array)
  #8 [internal function]: Craft\IndexerCommand-&gt;actionIndexTemplate('35262')
  #9 /craft/app/framework/console/CConsoleCommand.php(172): ReflectionMethod-&gt;invokeArgs(Object(Craft\IndexerCommand), Array)
  #10 /craft/app/framework/console/CConsoleCommandRunner.php(71): CConsoleCommand-&gt;run(Array)
  #11 /craft/app/framework/console/CConsoleApplication.php(92): CConsoleCommandRunner-&gt;run(Array)
  #12 /craft/app/framework/base/CApplication.php(185): CConsoleApplication-&gt;processRequest()
  #13 /craft/app/etc/console/yiic.php(81): CApplication-&gt;run()
  #14 /craft/app/etc/console/yiic(4): require_once('/Ind...')
  </code></pre>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-11-23T17:48:34.600Z
Comments.Text: Can you share the full stack trace leading up to that error?
Comments.UserDisplayName: Brad Bell
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-11-23T18:08:32.903Z
Comments.Text: @BradBell added it to the post.
Comments.UserDisplayName: Fred Carlsen
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-11-23T18:10:32.970Z
Comments.Text: Looks like another error is happening first, then the getTheme error happens when Craft tries to render the default "exception" template.  Try checking `craft/storage/runtime/logs` for the underlying error message on the first error.
Comments.UserDisplayName: Brad Bell
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-11-23T19:29:09.443Z
Comments.Text: @BradBell Looks like it's not finding the template, and is throwing a TemplateLoaderException. Where does it look for templates when running in the context of a command? The same call works in a controller. I also guess the templateloader should an exception in console mode more gracefully, as to not trigger the getTheme() error.
Comments.UserDisplayName: Fred Carlsen
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-11-23T19:42:46.457Z
Comments.Text: Agree the 2nd issue is a bug.  Try using setTemplatesPath to your plugin's template folder like so: http://craftcms.stackexchange.com/a/4392/57
Comments.UserDisplayName: Brad Bell
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-11-23T19:54:49.487Z
Comments.Text: That worked, by telling it to specifically look into the plugins template directory. Do you know where it looks by default when being run from console?
Comments.UserDisplayName: Fred Carlsen
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-11-23T19:56:37.670Z
Comments.Text: Either site or control panel template path... would have to dig into the code.  Can you add that as an official answer?  Will look into the 2nd bug.
Comments.UserDisplayName: Brad Bell
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-11-23T19:58:30.680Z
Comments.Text: Will do. I think it's useful to make this into a post about where it looks for console commands, so report back when you find out. Does it also make sense to make it consistent with how it works in a controller?
Comments.UserDisplayName: Fred Carlsen
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-11-23T20:02:47.853Z
Comments.Text: Guessing in the context of a console command it defaults to site: https://github.com/pixelandtonic/Craft-Release/blob/master/app/services/TemplatesService.php#L141
Comments.UserDisplayName: Brad Bell
Tags: <templating><console>
Title: Craft\ConsoleApp and its behaviors do not have a method or closure named "getTheme"
ThreadText: # Craft\ConsoleApp and its behaviors do not have a method or closure named "getTheme"
  
  (Asked by: username_0 on 2016-11-23)
  
  I'm trying to render a template from a console command, but i'm getting the following error:
  
  ```
  Craft\ConsoleApp and its behaviors do not have a method or closure named "getTheme"
  
  ```
  
  The code looks like this:
  
  ```
  public function actionIndexTemplate ($id = null)
  {
      $criteria          = craft()->elements->getCriteria(ElementType::Entry);
      $criteria->section = 'products';
      $criteria->limit   = 1;
      $criteria->id      = $id;
      $entry             = $criteria->first();
  
      if ( $entry ) {
          $output = craft()->templates->render('indexer/Product', [
              'element' => $entry
          ]);
          $data       = json_decode($output, $assoc = true);
      }
      else {
          echo "No entry found\n";
      }
  }
  
  ```
  
  And here is the stack trace:
  
  ```
  CException: Craft\ConsoleApp and its behaviors do not have a method or closure named "getTheme". in /craft/app/framework/base/CComponent.php:266
  Stack trace:
  #0 /craft/app/framework/base/CErrorHandler.php(390): CComponent->__call('getTheme', Array)
  #1 /craft/app/framework/base/CErrorHandler.php(340): CErrorHandler->getViewFile('exception', 500)
  #2 /craft/app/etc/errors/ErrorHandler.php(233): CErrorHandler->render('exception', Array)
  #3 /craft/app/etc/errors/ErrorHandler.php(137): Craft\ErrorHandler->handleTwigError(Object(Craft\TemplateLoaderException))
  #4 /craft/app/framework/base/CErrorHandler.php(131): Craft\ErrorHandler->handleException(Object(Craft\TemplateLoaderException))
  #5 /craft/app/framework/base/CApplication.php(750): CErrorHandler->handle(Object(CExceptionEvent))
  #6 [internal function]: CApplication->handleException(Object(Craft\TemplateLoaderException))
  #7 {main}%
  
  ```
  
  Here is the underlying error:
  
  ```
  2016/11/23 18:15:13 [error] [exception.Craft\TemplateLoaderException] Craft\TemplateLoaderException: Ikke i stand til å finne malen “indexer/Product”. in /craft/app/etc/templating/twigextensions/TemplateLoader.php:123
  Stack trace:
  #0 /craft/app/etc/templating/twigextensions/TemplateLoader.php(71): Craft\TemplateLoader->_findTemplate('indexer/P...')
  #1 /craft/app/vendor/twig/twig/lib/Twig/Environment.php(312): Craft\TemplateLoader->getCacheKey('indexer/P...')
  #2 /craft/app/vendor/twig/twig/lib/Twig/Environment.php(378): Twig_Environment->getTemplateClass('indexer/P...', NULL)
  #3 /craft/app/etc/templating/TwigEnvironment.php(61): Twig_Environment->loadTemplate('indexer/P...', NULL)
  #4 /craft/app/vendor/twig/twig/lib/Twig/Environment.php(347): Craft\TwigEnvironment->loadTemplate('indexer/P...')
  #5 /craft/app/services/TemplatesService.php(253): Twig_Environment->render('indexer/P...', Array)
  #6 /craft/plugins/indexer/services/Indexer_IndexService.php(136): Craft\TemplatesService->render('indexer/P...', Array)
  #7 /craft/plugins/indexer/consolecommands/IndexerCommand.php(93): Craft\Indexer_IndexService->renderTemplate(Array)
  #8 [internal function]: Craft\IndexerCommand->actionIndexTemplate('35262')
  #9 /craft/app/framework/console/CConsoleCommand.php(172): ReflectionMethod->invokeArgs(Object(Craft\IndexerCommand), Array)
  #10 /craft/app/framework/console/CConsoleCommandRunner.php(71): CConsoleCommand->run(Array)
  #11 /craft/app/framework/console/CConsoleApplication.php(92): CConsoleCommandRunner->run(Array)
  #12 /craft/app/framework/base/CApplication.php(185): CConsoleApplication->processRequest()
  #13 /craft/app/etc/console/yiic.php(81): CApplication->run()
  #14 /craft/app/etc/console/yiic(4): require_once('/Ind...')
  
  ```
  
  **Tags:** templating, console
  
  > **Comments:**
  > **username_1**: Can you share the full stack trace leading up to that error?  
  > **username_0**: @username_1 added it to the post.  
  > **username_1**: Looks like another error is happening first, then the getTheme error happens when Craft tries to render the default "exception" template.  Try checking `craft/storage/runtime/logs` for the underlying error message on the first error.  
  > **username_0**: @username_1 Looks like it's not finding the template, and is throwing a TemplateLoaderException. Where does it look for templates when running in the context of a command? The same call works in a controller. I also guess the templateloader should an exception in console mode more gracefully, as to not trigger the getTheme() error.  
  > **username_1**: Agree the 2nd issue is a bug.  Try using setTemplatesPath to your plugin's template folder like so: http://craftcms.stackexchange.com/a/4392/57  
  > **username_0**: That worked, by telling it to specifically look into the plugins template directory. Do you know where it looks by default when being run from console?  
  > **username_1**: Either site or control panel template path... would have to dig into the code.  Can you add that as an official answer?  Will look into the 2nd bug.  
  > **username_0**: Will do. I think it's useful to make this into a post about where it looks for console commands, so report back when you find out. Does it also make sense to make it consistent with how it works in a controller?  
  > **username_1**: Guessing in the context of a console command it defaults to site: https://github.com/pixelandtonic/Craft-Release/blob/master/app/services/TemplatesService.php#L141  
  
  ---
  
  ## 0 answers
  
  