<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>

CC BY-SA 3.0
2016-02-26T02:55:39.047Z
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...
RitterKnight
CC BY-SA 3.0
2016-02-26T03:46:39.473Z
@RitterKnight's suggestion is an option. Can you share some relevant plugin code?  Do you have an instance of the template from your plugin?
Brad Bell
<plugins><error-templates>
How to use getTemplateName() from within a plugin?
# 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

