Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2025-10-04 21:03:34

gaekwad
Server grease monkey
From: People's Republic of Cornwall
Registered: 2005-11-19
Posts: 4,523
Bitbucket GitHub

What's the least-crufty way to show the http response code?

I’d like to show the HTTP response code on a page. I’m curious if there’s a preferred way to do this.

We’ve got if_status as a conditional check for a supplied error (HTTP 4xx? Are there more?) code, and we’ve got error_status that outputs the aforementioned code. An HTTP 200 is a non-error status in Textpattern terminology, and so my route in to achieve this is:

<txp:if_status not status="200">
  <txp:error_status />
<txp:else />
  200
</txp:if_status>

Am I missing a magical tag that just outputs the HTTP response without the conditional check?

For bonus Internet magic beans: does Textpattern core emit any other non-error HTTP response codes over and above HTTP 200?

Offline

#2 2025-10-04 21:10:35

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 12,014
Website GitHub

Re: What's the least-crufty way to show the http response code?

That’s pretty much the best way. As far as I can recall, 200 is the only non-error we emit:

    $codes = array(
        '200' => 'OK',
        '301' => 'Moved Permanently',
        '302' => 'Found',
        '303' => 'See Other',
        '304' => 'Not Modified',
        '307' => 'Temporary Redirect',
        '308' => 'Permanent Redirect',
        '401' => 'Unauthorized',
        '403' => 'Forbidden',
        '404' => 'Not Found',
        '410' => 'Gone',
        '414' => 'Request-URI Too Long',
        '451' => 'Unavailable For Legal Reasons',
        '500' => 'Internal Server Error',
        '501' => 'Not Implemented',
        '503' => 'Service Unavailable'
    );

The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#3 2025-10-04 21:12:42

etc
Developer
Registered: 2010-11-11
Posts: 5,514
Website GitHub

Re: What's the least-crufty way to show the http response code?

Probably <txp:error_status default="200" />?

Offline

#4 2025-10-04 21:15:07

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 12,014
Website GitHub

Re: What's the least-crufty way to show the http response code?

etc wrote #340848:

Probably <txp:error_status default="200" />?

Oooh yeah, forgot that default was a global attribute. Good hack.


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#5 2025-10-04 21:20:58

gaekwad
Server grease monkey
From: People's Republic of Cornwall
Registered: 2005-11-19
Posts: 4,523
Bitbucket GitHub

Re: What's the least-crufty way to show the http response code?

etc wrote #340848:

Probably <txp:error_status default="200" />?

Ooh, clever. Thank you, etc!

Offline

Board footer

Powered by FluxBB