Learn

Response Codes

Have your users best interests in mind? Set your own response codes.

If you’re unsatisfied with the standard 200 or 404 response codes that Statamic will use by default, you can now specify a response code to use per piece of content. To do this, set the _response variable to the status code you want to use.

---
title: Forbidden Fruits
_template: 403-template
_response: 403
---
I'm sorry, but access to this is forbidden.

Using with Hooks

As of v1.7.6, Hooks now include a shortcut method for quickly setting the response code to be sent when triggered via URL.

As an example:

<?php
class Hooks_example extends Hooks
{
    /**
     * My example hook
     * URL-wise, would be: /TRIGGER/example/my_hook
     */
    public function example__my_hook()
    {
        // do whatever I need to do
        $computer = new Computer();
        $computer->getHardDrive()->format();

        // now I want to return status code 500
        // (pretend this is a good idea)
        $this->setStatusCode(500);
    }
}

You can set most of the standard response codes with this method.

This article was last updated on March 30th, 2016. Find an error? Please let us know!