Jump to content
Moritz Both

Makup regions, url segments and Wire404Exception

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.

Share this post

Link to post
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

Share this post

Link to post
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.

Share this post

Link to post
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.


Share this post

Link to post
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

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By louisstephens
      So I have been hard at work creating url segments for a template (api) and everything is working swimmingly in creating a simple end point for svelte.js. I have however, run into a few questions that I can wrap my head around.
      In my api template I have:
      if($input->urlSegment1 === 'clients') { header('Content-Type: application/json'); $clients = $pages->find("template=clients"); $client_array = array(); foreach ($clients as $client) { $id = $client->id; $title = $client->title; $url = $client->url; $clientName = $client->client_name; $clientColor = $client->client_color->value; $assigned = $client->assigned_to->user_full_name; $client_array[] = array( 'id' => $id, 'code' => $title, 'name' => $clientName, 'associated_users' => $assigned, 'url' => $url ); } $client_json = json_encode($client_array, true); echo $client_json; } The output json from this is:
      [ { "id":1644, "code":"abc", "name":"Test Name", "associated_users":null, "url":"\/pw\/clients\/abc\/" }, { "id": 1645, "code": "xyz", "name": "Test Name", "associated_users": null, "url": "\/pw\/clients\/xyz\/" }, ] I was curious is it possible to add in "clients" before this output json so it would appear as 
      clients: [ { "id":1644, "code":"abc", "name":"Test Name", "associated_users":null, "url":"\/pw\/clients\/abc\/" }, { "id": 1645, "code": "xyz", "name": "Test Name", "associated_users": null, "url": "\/pw\/clients\/xyz\/" }, ] I was not really sure of how to tackle this in my php code, and have spent more time than I care to admit trying to figure it out. Another question I have is that "associated_users" is returning null, which in this instance is correct. It is a multi page field that is set to pull a custom name field from the users template, ie "Louis Stephens" would be associated with the first page. I understand that I need to use a foreach to get the correct data, but I was really unsure of how to place this inside an array, or update the array with the new data. Any help with any of this would greatly be appreciated.
    • By rushy
      Hello. I have recently adopted PW markup regions and really like this way of working. However, I am also trying to learn how to use Ajax and I am not sure of a good way to use the two together. Has anyone got any experience, tips or hints on using them together? For ajax -  I've used a simple scheme where I have a "webservice" template and page that handles Ajax requests and returns the appropriate content wrapped with some markup for the requesting page. I have markup regions enabled and all my pages (bar webservice) include a _main.php which brings in the headers, a default body and the footer. My javascript intercepts the page links and does my ajax call to webservice and that sends back the appropriate markup which is then placed by in the div #body defined in _main.php.  Does this seem a reasonable way to work? I guess I am looking for some advice before I invest too much time going the wrong way!
      Any guidance, remarks,  comments, or a nudge in the right direction greatly appreciated.
    • By hansv
      Hi everybody
      I want to catch a variable from outside processwire into _main.php
      if(isset($_GET['u']) && $_GET['u'] !== ''){ $gebruikersnaam = $_GET['u']; ... ... This is working fine in a php file in a non processwire environment. 
      In a processwire environment, I get the variable when I refer to /site/templates/_main.php but a great part of my template-code is not shown. 
      From outside processwire I refer to    mydomain/index.php.  If I place   $gebruikersnaam = $_GET['u'];  in index.php, how can I pass through my variable to _main.php?   Or is there an other solution?
    • By darrenc
      lets say, in _main.php I have some placeholder regions for content/sidebar
      <div id="content">foo</div> <div id="sidebar">bar</div> in my home.php template, maybe i don't want the sidebar div at all. But when I put in the intentionally blank code
      <region id="sidebar"></region> I simply make my sidebar div blank, it doesn't remove it.
      Q: Is there a slick way to simply nuke that div#sidebar entirely from markup?
    • By EyeDentify
      I as have been a bit confused for some time about how the "Markup Regions" functionality in Processwire worked.
      But i have know read a bit more and think that i am getting to grips with it. And Markup Regions is going to be huge.

      To aid me in understanding Markup Regions better i started to read the Source code for the new "Regular" theme in conjunction with the Blog about the markup regions.
      It helped me a great deal to understand the basics and more fine details of it.

      A tip is to open both links and use the Source code of the "Regular" theme while reading the blog post.
      The Source code:
      The Blog post:
      I hope this could help others starting out with markup regions.
      Just take it slow and read it a couple a times and soon you will see the greatness of markup regions.

  • Create New...