Sage9 controller selection for custom page templates

I can’t seem to get page templates to function with soberwp’s controllers. The “default” hierarchies seem to work fine. e.g. a page called “members” will pick up controllers/PageMembers.php or controllers/Page.php if PageMembers.php doesn’t exist. FrontPage.php works fine for the page defined as the front page, etc. It’s just the use of page templates I can’t get to work.

Example:

  • I have a page called “Legal & Ethics”, with a parent page called Members"
  • URL is mysite.com/members/legal-and-ethics
  • This page has a Page Template called “Section Page”
  • /views/section-page.blade.php defines the page template named “Section Page”
  • This blade template is used properly
  • a matching /controllers/SectionPage.php defines a class named SectionPage
  • The class is not used, instead Page.php is used

The Hierarchy debugger outputs this:

Hierarchy Debugger:
controllers/app.php
controllers/index.php
controllers/resources/views/singular.php
controllers/singular.php
controllers/views/singular.php
controllers/resources/views/page.php
controllers/page.php
controllers/views/page.php
controllers/resources/views/page-76.php
controllers/page-76.php
controllers/views/page-76.php
controllers/resources/views/page-legal-and-ethics.php
controllers/page-legal-and-ethics.php
controllers/views/page-legal-and-ethics.php

What am I missing?

I believe I ran into the same issue the other day, and I think it was this PR that fixed it for me: https://github.com/roots/sage/pull/1980

1 Like

Thanks, that pointed me in the right direction to maybe make some progress. The problem solved by that PR is similar, but deals with loading the template itself, not the controller. Just like sage, soberwp is ignoring any template with .blade.php in the name, but that is how the template name is stored in the db. So, custom page templates get passed right over.

The offending method is vendor/soberwp/src/Loader->setDocumentClasses

My mistake, I meant to post this PR: https://github.com/roots/sage/pull/1941/commits

1 Like

Perfect, that fixes the problem. I guess I’ll stop writing this soberwp/Controller issue. :slight_smile:

Thank you!

1 Like