We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

How can I determine if the 404 template is being displayed?

How Do I?

User 1FSajseJP's avatar
User 1FSajseJP
6 posts
3 months ago
User 1FSajseJP's avatar User 1FSajseJP

EE 6, noticing that when the 404 template is returned due to a bad URL (not a redirect tag inside an exp:channel:entries tag with require_entry, for example), that the original URL remains in the browser, but the 404 template content is displayed.

I have a site with ads that are displayed globally.. I want to prevent the ads from being displayed on that 404 page.. Initially, I approached it with a conditional like :

{if segment_1 != "404"}

But, since the 404 doesn’t redirect (change the URL), that approach won’t work.. Any thoughts of how I Can determine if the 404 template is being displayed, so I can do a similar conditional around the google ad code?

       
User BULfYYMv's avatar
User BULfYYMv
25 posts
3 months ago
User BULfYYMv's avatar User BULfYYMv

I wonder if there’s a way to check the http_header

       
User BULfYYMv's avatar
User BULfYYMv
25 posts
3 months ago
User BULfYYMv's avatar User BULfYYMv

or…

       
User BULfYYMv's avatar
User BULfYYMv
25 posts
3 months ago
User BULfYYMv's avatar User BULfYYMv

just check the template name

       
User BULfYYMv's avatar
User BULfYYMv
25 posts
3 months ago
User BULfYYMv's avatar User BULfYYMv

https://docs.expressionengine.com/latest/templates/globals/single-variables.html#template_name

       
User BULfYYMv's avatar
User BULfYYMv
25 posts
3 months ago
User BULfYYMv's avatar User BULfYYMv
{if '{template_name}' == '404'}
 This is 404 template
{/if}

{if '{template_name}' != '404'}
 This is not 404 template
{/if}
       
User 1FSajseJP's avatar
User 1FSajseJP
6 posts
3 months ago
User 1FSajseJP's avatar User 1FSajseJP

AH! THanks @Jared I’ll give that a try.. that’s what I was looking for.

       
User BULfYYMv's avatar
User BULfYYMv
25 posts
3 months ago
User BULfYYMv's avatar User BULfYYMv

Tried it and it does parse

       
User 1FSajseJP's avatar
User 1FSajseJP
6 posts
3 months ago
User 1FSajseJP's avatar User 1FSajseJP

Yep.. that works.. However, i have ea 404 template group, and the template name is “index”.. BUt, I can use {template_group} as the variable and that works.

       
User BULfYYMv's avatar
User BULfYYMv
25 posts
3 months ago
User BULfYYMv's avatar User BULfYYMv

Yeah, seems like that would work.

       
User 1FSajseJP's avatar
User 1FSajseJP
6 posts
3 months ago
User 1FSajseJP's avatar User 1FSajseJP

Ok.. Well, not working directly inside the layout.. I think I’ll have to set it up as a layout variable. But, this takes me where I need to go..Thanks again!

       
User BULfYYMv's avatar
User BULfYYMv
25 posts
3 months ago
User BULfYYMv's avatar User BULfYYMv

I think another option might be to use the request addon…

{exp:request:get name="status"}

       
User 1FSajseJP's avatar
User 1FSajseJP
6 posts
3 months ago
User 1FSajseJP's avatar User 1FSajseJP

Yep.. Just confiming.. I set up a layout:set variable in my 404 template and then use that to test on the layout.. perfect.

       
User BULfYYMv's avatar
User BULfYYMv
25 posts
3 months ago
User BULfYYMv's avatar User BULfYYMv

Nice. I’m testing the request addon… not doing what I thought.

       
User BULfYYMv's avatar
User BULfYYMv
25 posts
3 months ago
User BULfYYMv's avatar User BULfYYMv

or anything at all

       
1 2

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.