My site's index page template uses switchee to determine whether to serve up index (home) page or a "single page" entry from the static channel.
I'm attempting to set up a 404 page for the site, and created a 404 template in the default site template group.
Once I set up 404s, all the "static" entries display as 404 instead.
I'd like to keep the option of single pages at the segment_1 level, so the site can add other single-purpose landing pages over time.
My Global Template Preferences:
- Enable Strict URLs Yes, No, (this setting makes no difference)
- 404 Page: site/404 (when set to None, things display okay)
Index template contains the following:
{exp:switchee variable="{segment_1}" parse="inward"}
{!-- ----- HOME PAGE ----- --}
{case value="index|''"}
...
{/case}
{!-- ----- Static Pages + Sidebar Asides ------ --}
{case default="Yes"}
{exp:channel:entries
channel="static"
limit="1"
dynamic="no"
disable="categories"
require_entry="yes"
url_title="{segment_1}"
}
{if switchee_no_results}{redirect="404"}{/if}
...
{/exp:channel:entries}
{/case}
{/exp:switchee}
EDIT NOTE (and apology): When I first posted this, I inadvertantly pasted the {if switchee_no_results} outside the {exp:channel:entries} tag pair. But it was inside that tag pair in my actual code. So sorry to have misled you. It was not my intention.
(the if switchee_no_results, require_entry, url_title="{segment_1}" were all recently added while trying to get things working with 404s)
Here is Template Debugging for the about page (an entry in the static channel)
When Global Template Preferences are set to strict=No and 404 Page=None:
(0.000006 / 4.56MB) - Begin Template Processing -
(0.000940 / 4.60MB) URI: about
(0.000952 / 4.60MB) Path.php Template: /
(0.000963 / 4.60MB) Retrieving Template
(0.000972 / 4.60MB) Parsing Template URI
(0.005528 / 4.80MB) Showing index. Template not found: about
(0.005556 / 4.81MB) Retrieving Template from Database: site/index
(0.006652 / 4.81MB) Template Found
(0.007026 / 4.82MB) Retrieving Template from File
When Global Template Preferences changed to 404 Page=site/404
(0.000005 / 4.56MB) - Begin Template Processing -
(0.000966 / 4.60MB) URI: about
(0.000978 / 4.60MB) Path.php Template: /
(0.000989 / 4.60MB) Retrieving Template
(0.000998 / 4.60MB) Parsing Template URI
(0.005462 / 4.80MB) Template group and template not found, showing 404 page
Other things I have tried (which have not made any difference):
{case value="{segment_1}" default="yes"}
Based on James Smith's URL schematic which he mentions here on EESE (topic: strict urls), I fear I broke some cardinal rule about segment_1. I hope not.
Are you aware of any way I can keep the basic setup as described (a single, index template uses switchee to serve up both home page and single entries in the static channel) and make the 404s work right?
UPDATED: I took this conversation to the switchee support forum on devotee, and based on Mark Croxton's response, I implemented a fix and describe it below.