I wondered if we could embellish from this answer?

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?

  • 1
    Similar to this question minus the templating? Not sure what you're trying to do but http_response_code() could work... Feb 26 '16 at 2:55
  • @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
    Feb 26 '16 at 3:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.