Jump to content

Makup regions, url segments and Wire404Exception

Moritz Both

Recommended Posts


For our PW project we use markup regions and, for one template, url segments. The documentation recommends throwing a new Wire404Exception() from the template when the code concludes that the url segments from the request are invalid, and so we do.

However, the 404 page is not displayed properly. Viewing the page source in the browser we can see that the original, unmodified markup region contents from our _init.php file is prepended to the correct html output, messing the whole page up.

Any advice is greatly appreciated.

Link to comment
Share on other sites

The 404 page uses the basic-page.php template file unless you have changed it on admin. Take a look at how Ryan implemented a PW region debug on the Uikit "Regular" site profile, it may help you figure it out:

<?php if(config()->debug && user()->isSuperuser()): // display region debugging info ?>
	<section id='debug' class='uk-section uk-section-muted'>	
		<div class='uk-container'>
<?php endif; ?>


  • Like 1
Link to comment
Share on other sites

Sergio, thanks for your answer.

Unfortunately I am not able to connect your input with my problem.

It is true that I can establish a "debug" region with markup regions, but what should I display there? The problem is the inclusion of my "_init.php", which defines standard values for all markup regions, as-is, into the output sent to the browser before the actual 404 page.

The _init.php contents seems still to be in the output buffer when the correct 404 page markup is added to it.

Here is what I see when I look at the page source in my browser (commented, redacted and shortened):

[source starts with original contents of my _init.php]
<!-- Content for default markup regions available on all pages ==== -->
<!-- Page title -->
<title id="page_title">Kurs</title>
<!-- Styles -->
<link pw-replace="page_styles" rel="stylesheet" type="text/css" href="/bmw/site/templates/styles/main.css">

[... more original contents from _init.php follows ... we tune in again right before the end of _init.php ...]

<div pw-replace="footerinfo">
    <a href="/bmw/datenschutz/">Datenschutz</a> / 
    <a href="/bmw/impressum/">Impressum</a>
<!DOCTYPE html>
<html lang="de">

    <meta http-equiv="content-type" content="text/html; charset=utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=3.0, user-scalable=1">
    <meta name="description" content="" />
    <title>404 Page | bildungsverein.de</title>
    <link rel="stylesheet" type="text/css" href="/bmw/site/templates/styles/main.css">

[... bingo, after _init.php the correct page starts....]

As you can see, _init.php is sent to the browser unmodified although its contents should never have been sent. After it, the correct 404 page follows. The 404 page is the contents of my _main.php, filled with information from the 404 page template, and using default values from _init.php.

Please advise how to debug this. Thank you.

Link to comment
Share on other sites

Hi Moritz, I see. Without seeing your _init file, I wonder why did you set the default regions there opposed to set them in _main.php or other template that's appended and not prepended?

As _init.php is prepended (as set in the default PW config file) the region's content will appear on all page before they are rendered, unless you replace that region on the 404 template file (basic-page), like:

<div pw-replace="footerinfo">
    <!-- nothing -->

Using the debug, I can see it at the bottom of my 404 page. See that the first line shows the region I set on _init.php (copied from yours) and it being replaced on the third line.


Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Create New...