3

It appears that when using the recommended method of {if no_results}{redirect=404}{/if} in a template that uses the template layout feature, it duplicates the layout, if a layout is also used on the actual 404 template. The 404 template lives at errors/404 it includes the following:

errors/404 template

{layout="_layouts/master}
404 Error Content Here

When viewing a normal page that 404s (sitename.com/pagedoesntexist) it works as expected.

_layouts/master template

{layout="_layouts/_global}
   {embed="_embeds/header"}
     {layout:contents}
   {embed="_embeds/footer"}

On instances that do not work as expected it's set up like the following:

Sample template using the 404 redirect tag

{layout="_layouts/master}
{exp:channel:entries}
   Content Here

   {if no_results}
     {redirect=404}
   {/if}
{/exp:channel:entries}

This results in the file rendering the master layout twice (double header + footer in my instance) because the {redirect=404} tag is essentially copying the results of the /errors/404 template into the template that contains no results instead of displaying the 404 page as usual.

Is there a way around this bug, preferably that doesn't require enabling php in templates?

5

This is a known bug in EE 2.9.0: https://support.ellislab.com/bugs/detail/20471/site-index-template-is-rendered-after-the-404-template

The fix from that thread:

Open system/expressionengine/libraries/Template.php and find this code on line 2236:

ee()->output->out_type = "404";
ee()->output->set_output($out);
ee()->output->_display();

And REPLACE it with this:

ee()->output->out_type = "404";
ee()->output->set_output($out);
ee()->output->_display();
exit;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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