When I get a 404 page, the URL in the browser remains pointing to the page I was trying to reach. ie. the address bar will show domain.com/unreachable-page not domain.com/404. Which is fine and, I believe, correct behaviour. However…

That being the case, is there any way to target the 404 template with a conditional? (In this case, from within an embed or snippet that appears on every template -- I wish to have some different content for the 404 template). It would seem that segments are not going to be much help here, so I wondered if there is another way.


{if is_404_template}
    // Display something


  • 1
    Can you give some examples of your desired end result? I don't understand from the question what you mean by "target", and which content is conditional by what criteria. May 20, 2014 at 20:11
  • Not sure that edit clarifies it for me, Derek Hogue, since the 404 template is always going to be used on 404s. I don't know when that conditional would ever be useful. May 20, 2014 at 21:24
  • Hi Derek and Derek; sorry for the ambiguity. The scenario I have at hand is that a 'snp_html_head' snippet which includes (amongst other thing) my SEO-Lite tag. I drop that tag in with different parameters -- or omit it entirely -- depending upon the host template, accomplished via segment checking in Switchee. Currently I can't do this for the 404 template, hence my question. Robson's preload variable line of attack (see below) might provide a workaround though.
    – RickL
    May 21, 2014 at 7:44
  • (So, yes, Derek Hogue's example is exactly what I'm trying to achieve).
    – RickL
    May 21, 2014 at 7:45
  • Sorry, it sounds like you are trying to search optimize your 404 page. I would think all search engines would exclude 404 pages from their indexes, no? At least those pages that return a proper 404 error code.
    – AllInOne
    May 21, 2014 at 13:20

1 Answer 1


Since your 404 template is one specific, you can, of course, add a Preload Replace Variable to it.

Let's say you have a snippet which appears on every template called {snip-html}:

{preload_replace:pre-root_class=""}{!-- setting a default value --}
<html class="{pre-root_class}">

On the template set to be your 404, you can override this value:


This template will have the snippet parsed:

<html class="{pre-root_class}">

Then, the first preload replace variable:

<html class="404">

Then, the second one will not find where to go and will just disappear:

<html class="404">

See? You created a variable for this specific template.

I tried to create a simple example adapting something I already used, because I don't know exactly what you need, but you can, of course, use this on a conditional or make adaptations.

  • Hi Robson, and thanks for that suggestion. I don't think it's going to work in my case because I'm selectively including or omitting EE code in the HTML head tag, not just adding HTML markup content. The prohibition of including EE tags in preload variables I think throws this one out of the ring (in this case), but thanks for the suggestion.
    – RickL
    May 21, 2014 at 8:10
  • @RickLecoat, you can use a variable around the Preload Replace.
    – Sobral
    May 21, 2014 at 11:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.