Controller only ran once when rendering several pages?

For the StaticBuilder plugin, during one HTTP request I’m rendering dozens or hundreds of pages. In my tests (on not so simple website), each controller is only ran once at most.

This means that if you have those two pages:

  • blog/category1/posts.txt
  • blog/category2/posts.txt

And the posts.php controller gets the page’s children, filters it and sends it to the template, then:

  1. It seems that posts.php is only ran once.
  2. The blog/category2 page will be rendered without an error, but it will list posts from category1.

The exact code used is here:
https://github.com/fvsch/kirby-staticbuilder/blob/master/core/builder.php#L207-L229

If anyone who knows Kirby’s internals wants to chime in, it would be much appreciated. :slight_smile:

PS: tested with 2.3 (develop branch from a few days ago).
PPS: plugin issue is https://github.com/fvsch/kirby-staticbuilder/issues/9

That looks like a bug to me.
However the controller results aren’t cached anywhere, so I can’t really tell why this is happening.

What happens if you manually run $page->controller() from your plugin? This isn’t the solution, but it may give some insights into what is happening. Please also try updating to the release version of Kirby 2.3.0 just to make sure.

Running $page->controller() directly doesn’t help either. (It returns an array with values the first time, and an empty array after that.) The issue seems to be in the registry. Apparently it can be fixed by switching from include_once to include, but maybe that’s not the best option. I opened an issue.

This issue also made me realise I had another problem, so I opened another issue:

Thanks, that helped a lot with finding the issue. I have commented over on GitHub. Discussion continues there.