ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Updated to 1.6...can't find where to hide templates

June 21, 2007 1:04pm

Subscribe [4]
  • #16 / Jun 22, 2007 3:36pm

    Derek Jones

    7561 posts

    Well Access control will serve up a different template, which doesn’t sound like what you want, it sounds like you want a 404, so you’d leave all Access open to that template, and place the code in there, switching PHP parsing on in the template preferences.

  • #17 / Jun 22, 2007 3:45pm

    Deron Sizemore

    1033 posts

    But by allowing all access open and placing the PHP header code above into the index template, when (if) someone tries to access that template, they wont see my 404 Error page will they?  They will just see a generic “404 Not Found” message in the top left side of the screen…

  • #18 / Jun 22, 2007 3:57pm

    Derek Jones

    7561 posts

    PHP set to “Output” parsing stage:

    <?php
    header("HTTP/1.0 404 Not Found");
    ?>
    
    ...your template code…
    
    <?php
    exit;
    ?>
  • #19 / Jun 22, 2007 4:10pm

    Deron Sizemore

    1033 posts

    I’m sorry to be such a hassle here, but this doesn’t seem to be working out.  I’m about to just leave the templates blank and be done with it.  😊

    I went into the preferences and set the index template to allow PHP and it was also set to “output.”

    Here is the template code I’m using for the index template:

    <?php
    header("HTTP/1.0 404 Not Found");
    ?>
    
    {embed="includes/.meta" page_title="404 File Not Found - Random Jabber"}
    
    <body id="home">
    
    <div id="wrapper" class="clearfix">
    
        <div id="masthead" class="clearfix">
            {embed="includes/.header"}
        </div>
    
        <div id="content" class="clearfix">
            <div id="maincontent">
                    <h1 class="notfound">404 File Not Found!</h1>
                    Sorry, but the page you're looking for could not be found.  If you believe there is a problem please <a href="http://{path=">contact me</a> and I will investigate the problem.  Thank you.
            </div>
    
            <div id="secondarycontent">
                {embed="includes/.secondary"}
            </div>
        </div>
    
    <div id="footer">
    {embed="includes/.footer"}
    </div>
    
    </div>
    
    </body>
    </html>
    
    <?php
    exit;
    ?>

    And here is the result:  http://www.randomjabber.com/includes

    By restricting access and redirecting to my 404 Error template, isn’t that essentially the same thing as what EE is doing when I go into the global template preferences and set the 404 error page to my 404 error template?  Or does EE throw the 404 headers in there automatically in that situation?

  • #20 / Jun 22, 2007 4:12pm

    Derek Jones

    7561 posts

    Ah, well you won’t be able to do embeds, because the PHP exits the script before any subtemplates are parsed.  View your 404 page in the browser, and just cut and paste it’s rendered source HTML, so this particular template will be free of tags.

  • #21 / Jun 22, 2007 4:46pm

    Deron Sizemore

    1033 posts

    I see.  It seems the result is recognizing my exp tags for recent posts, etc… (I couldn’t just copy the html source as I have a “secondary” embed which holds the dynamic information in my sidebar) but it doesn’t seem to be recognizing my stylesheet.  Is that another downfall of this?

  • #22 / Jun 22, 2007 4:56pm

    Derek Jones

    7561 posts

    It’s fairly simple, Deron; I think you’re just trying to absorb too much at once.

    1) You need PHP to send the 404 header
    2) You need to exit ExpressionEngine or it will still try to send its own headers, which will result in errors
    3) Because you are exiting ExpressionEngine during the parsing of the parent template, you must keep all content on this single template.
    4) You can use any tags you like in the template, except things parsed after PHP on Output.  Without getting into the nitty gritty of parse order, that means that things like Weblog tags are fine.  Template global variables and embed tags, however, are not.

    So essentially, you just need to combine your templates that you use to build your 404 page into a single template (for this page only, I’m not suggesting you have to do that for the actual 404 template), and work from there.  If it’s all too much trouble, that’s fine too; I’m just giving you options to do what you’re describing that you want to happen.

  • #23 / Jun 22, 2007 4:59pm

    Derek Jones

    7561 posts

    Actually, I just thought of another solution.  Create a template includes/exit and enable PHP parsing and add just:

    <?php exit; ?>

    In includes/index cut and paste your full 404 template, as is.  Then at the very very bottom, add:

    {embed="includes/exit"}

    That should make sure that everything you want gets parsed, including embed tags prior to this one, and that the script still exits properly.  Template global variables, though, will still not work with this, as they are parsed at the very very end.

  • #24 / Jun 22, 2007 5:01pm

    Derek Jones

    7561 posts

    Never only a single way to do things, you could also just use this PHP instead of the header() commands.  Then you can do whatever you want, ignoring parsing rules, and just let EE do its thing.

    <?php
    global $TMPL, $OUT;
    $OUT->out_type = '404';
    $TMPL->template_type = '404';
    ?>
  • #25 / Jun 23, 2007 5:16pm

    Deron Sizemore

    1033 posts

    Hi Derek.  Thanks again for helping me out with this.  I went with your last suggestion so I could use embeds in the template (seemed easier to me).  I wanted to post my template and just make sure I’ve got it right, cause when I say I’m PHP illiterate, I seriously know no PHP.  I don’t know what you’re talking about when you talk about parsing rules, headers, and the code you gave me above, I have no idea what it means. 

    But anyway, here is my “includes/index” template.

    <?php
    global $TMPL, $OUT;
    $OUT->out_type = '404';
    $TMPL->template_type = '404';
    ?> 
    
    {embed="includes/.meta" page_title="404 File Not Found - Random Jabber"}
    
    <body id="home">
    
    <div id="wrapper" class="clearfix">
    
        <div id="masthead" class="clearfix">
            {embed="includes/.header"}
        </div>
    
        <div id="content" class="clearfix">
            <div id="maincontent">
                    <h1 class="notfound">404 File Not Found!</h1>
                    Sorry, but the page you're looking for could not be found.  If you believe there is a problem please <a href="http://{path=">contact me</a> and I will investigate the problem.  Thank you.
            </div>
    
            <div id="secondarycontent">
                {embed="includes/.secondary"}
            </div>
        </div>
    
    <div id="footer">
    {embed="includes/.footer"}
    </div>
    
    </div>
    
    </body>
    </html>
  • #26 / Jun 23, 2007 5:33pm

    Derek Jones

    7561 posts

    It looks good Deron, and I tested it on your site; it is sending the proper 404 headers.

  • #27 / Jun 23, 2007 7:07pm

    Deron Sizemore

    1033 posts

    Cool, thanks!

    What do you use to check the site headers?  I used http://www.seoconsultants.com/tools/headers.asp and found that when I tested http://www.randomjabber.com/blog/404-error (my 404 error template) that it does not display 404 headers.  I’ve set this template as the 404 error template in my global template preferences.  Is there something else I should do?

  • #28 / Jun 24, 2007 2:26am

    Derek Jones

    7561 posts

    It’s only going to show 404 if it’s being served in response to a template that doesn’t exist.  Accessing it directly, well, it exists, so it’s not going to 404.  There are browser extensions, scripts, and addons for pretty much whatever browser you use that will let you examine headers.  Google for that for whatever browser you use; you’ll find something.

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases