Body: <p>I wondered if we could embellish from <a href="https://craftcms.stackexchange.com/questions/449/how-can-i-make-a-template-output-its-own-filename#answer-450">this answer</a>?</p>
  
  <p>I'm developing a plugin where at some point it needs to detect if the user is currently on one of the error pages (400, 403, 404, 500, or 503). </p>
  
  <p>I'm not sure of any built in methods within craft, so I figured an easier solution would be to just check the file name being used. Php's <code>__FILE__</code> method refers to the .php file it was called from. I can't seem to grasp how to use <code>getTemplateName()</code> within a plugin. </p>
  
  <p>Is there a better way to detect the error page, or a clean way of detecting the template file being used?</p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-02-26T02:55:39.047Z
Comments.Text: Similar to [this question](http://craftcms.stackexchange.com/questions/13491/can-you-get-the-http-status-code-in-twig-templates/) minus the templating? Not sure what you're trying to do but ``http_response_code()`` could work...
Comments.UserDisplayName: RitterKnight
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-02-26T03:46:39.473Z
Comments.Text: @RitterKnight's suggestion is an option. Can you share some relevant plugin code?  Do you have an instance of the template from your plugin?
Comments.UserDisplayName: Brad Bell
Tags: <plugins><error-templates>
Title: How to use getTemplateName() from within a plugin?
ThreadText: # How to use getTemplateName() from within a plugin?
  
  (Asked by: username_0 on 2016-02-26)
  
  I wondered if we could embellish from [this answer](https://craftcms.stackexchange.com/questions/449/how-can-i-make-a-template-output-its-own-filename#answer-450)?
  
  I'm developing a plugin where at some point it needs to detect if the user is currently on one of the error pages (400, 403, 404, 500, or 503).
  
  I'm not sure of any built in methods within craft, so I figured an easier solution would be to just check the file name being used. Php's `__FILE__` method refers to the .php file it was called from. I can't seem to grasp how to use `getTemplateName()` within a plugin.
  
  Is there a better way to detect the error page, or a clean way of detecting the template file being used?
  
  **Tags:** plugins, error-templates
  
  > **Comments:**
  > **username_1**: Similar to [this question](http://craftcms.stackexchange.com/questions/13491/can-you-get-the-http-status-code-in-twig-templates/) minus the templating? Not sure what you're trying to do but ``http_response_code()`` could work...  
  > **username_2**: @username_1's suggestion is an option. Can you share some relevant plugin code?  Do you have an instance of the template from your plugin?  
  
  ---
  
  ## 0 answers
  
  