Jump to content

Recommended Posts

Posted

Hi there,

I have a single page that when hit executes twice. The page references a urlSegment - that's all there is that is different about the page to the others that just load once, as expected.

Any ideas what might be happening here or perhaps some way to track this down? I have tracked right through the code and when it gets to the very end, I find myself back on the first line of the template file once again?

Cheers.

Posted

What XDebug tells me is that the following line:

$page->relNextUrl = $nextUrl;

Where $nextUrl is equal to the value:

/ProcessWire/gallery/ladies/zowie/page2

Is for some reason, causing the issue? If I comment that line out, the page only executes once?

Posted

If I do the following:

$t->set('relNextUrl', $nextUrl);

So, assign the value to the TemplateFile instance and not the $page variable, I don't get the page firing twice.

So, for some reason, assigning the value of the rel=next URL to the $page instance seems to trigger the firing of the page, twice?

Posted

@Soma - the reason I knew this was happening was because:

if ($page->layout) {

include("./markup/layouts/{$page->layout}.php");

I had a break-point set on the "include" line above on the main template. I noticed that it stopped twice when I loaded the page in question.

Had I not set the break-point, I probably wouldn't have noticed the issue with the page.

So, XDebug rocks! ;)

Posted

Well I don't think anybody can reproduce and give an answer to what you're saying without knowing what exactly you're doing, since there's possibly a million ways to build your templates.

Posted

No there aren't.

$page->myvar = "hello";
echo $page->myvar;

But I don't know what is has to do with what you experience.

What I believe maybe (although can't say for sure as I don't see enough code) is that you have a main template that "renders" then include another page which renders again. So PW "renders" 2 times. If you would hook on "Page::render" it will get outputted twice.

Posted

>But I don't know what is has to do with what you experience.

I don't either, except for what apparently "fixed" the issue.

I dynamically created a Template object that needed a value so I attached that value to the page variable instance and inside the template file, it accessed the value through the page variable. In this case, the whole page rendered twice.

When I changed the template file to look for the same value but from a "local" variable and did $template->set('variable_name', 'url/value'), the whole page renders only once, just as I would expect.

So, this is the reason I asked about usage of the page variable for storing user defined values. Because the value I was storing was a rel next URL, I just wondered whether its URL structure somehow "confused" PW?

Thanks any way.

Posted

I have a normal page. In the template php file for that page I have this:

include("head.inc");

$page->layout = "text.php";
$page->myvar = "myvar1";

if($page->layout){
   include("./markup/{$page->layout}");
   echo "included...";
}

include("foot.inc");

And in the included php I have

echo $page->myvar;
echo $page->body;

All works fine and I don't see anything rendered or executed (whatever that means) twice.

So I can't reproduce it.

Posted

Agreed, all of my pages work as expected too. Like you said earlier, my template mechanism is different so you aren't easily able to recreate my scenario. I have it working fine now, but I would dearly like to know why it doesn't work in a completely reasonable alternative.

Posted

Well I give up. :)

That's exactly what I was trying to pull out of you! Without knowing/seeing your exact template setup I can't tell or help.

Posted

If I can isolate it down to a small reproducible test case, I will. Then you could cast your large green alien eyes over it ;)

Posted

My supposed "fix" wasn't a fix at all :(

When I corrected the error in my own logic, the guilty page is now nicely rendering on two occasions despite it only being called once via its URL. Here are the steps:

Template file called page-listing.php

Inside page-listing.php, a small helper template is rendered file as follows:

$t = new TemplateFile(wire('config')->paths->templates . 'markup/helpers/album-photo.php');
$album = $pages->get("/albums/{$input->urlSegment(1)}");
list($prevUrl, $nextUrl, $albumImages) = prevNextImagePaginator($album);

$page->metaTitle = $album->get('meta_title|page_h1|title');
$page->metaTitle = $album->meta_desc;
$page->relPrevUrl = $prevUrl;
$page->relNextUrl = $nextUrl;

$t->set('albumImages', $albumImages);
$t->set('segmentAlbum', $album);
$page->outBody .= $t->render();

At the bottom of page-listing.php, below the above code is:

include("./markup/index.php");

index.php contains the default layout and particularly:

if ($page->layout) {
include("./markup/layouts/{$page->layout}.php");
...

It is the above code that has the breakpoint set that is being hit twice despite calling the page only once?

Any ideas?

Posted

In my index.php file, I have the following code:

   <? if ($page->relPrevUrl) echo "<link rel=\"prev\" href=\"{$page->relPrevUrl}\" />", PHP_EOL; ?>
   <? if ($page->relNextUrl) echo "<link rel=\"next\" href=\"{$page->relNextUrl}\" />", PHP_EOL; ?>

Some progress. If I comment out the above code, the page is not executed twice! This seems to be the real issue although there doesn't seem to be anything inherently wrong with this code?

Ideas?

Posted

I've also changed the code to the following:

   <? if ($page->relPrevUrl) { ?>
       <link rel="prev" href="<?=$page->relPrevUrl?>" />
   <? } ?>

   <? if ($page->relNextUrl) { ?>
       <link rel="next" href="<?=$page->relNextUrl?>" />
   <? } ?>

This still causes the double page hit.

Posted

So you get whatever is in markup/layouts/{$page->layout}.php twice in your final html? If so, then there has to be another inclusion of markup/index.php somewhere. Or a loop in page-listing.php so that the include line gets executed twice. Or a loop in markup/index.php so that the layout gets included twice.

But I'm a bit confused: you're saying you wouldn't have found the issue without the breakpoint. So does that mean the html output is ok, and nothing is duplicated there? Then you wouldn't have an actual problem, other than a crazy debugger maybe :). If the layout template was actually executed twice you'd definitely have the output twice in your html. Just checking I've understood you right.

Posted

Hi nik,

I don't get duplicated output. The HTML is perfect except that the template file specified in the PW template (page-listing.php) runs twice, right from the start. It's called by PW; it's not under my direct control. It's as though the page has redirected to itself so, it just re-renders the whole page so, the markup is perfect, not duplicated.

Remember, if I comment out the two lines that specify link rel/prev - it only runs once. Every other page on the site only runs once <shrug>?

This is crazy.

Thanks.

Posted

The plot thickens ...

The first time, the REQUEST_URI is /ProcessWire/gallery/ladies/zowie/

The second time,

the REQUEST_URI is /ProcessWire/gallery/ladies/zowie/page2 (as is the REDIRECT_URL)

So, it seems that the page is being called twice, and the influence seems to be the link rel=next value.

Something seems to be happening outside of my control. I'm not redirecting to page2 or anything like that; I'm only trying to output the link value in the page <head> which is correctly specified as /ProcessWire/gallery/ladies/zowie/page2 when the page is first called.

Posted

Can you do a var_dump on $page->prevNext

What XDebug tells me is that the following line:

$page->relNextUrl = $nextUrl;

Where $nextUrl is equal to the value:

/ProcessWire/gallery/ladies/zowie/page2

Is for some reason, causing the issue? If I comment that line out, the page only executes once?

And what type is the value you get from $nextUrl?

Can you try without setting it to page and just use the $nextUrl and not $page->?

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.
×
×
  • Create New...