Jump to content

Recommended Posts

Posted

Thanks @MarkE - that's basically what I had to do. The difference however is that when hooking on saveReady for a just cloned page, the id is 0 even though it is a valid page and not a null page.

  • 5 months later...
Posted

BasicPagePage.php

class BasicPagePage extends Page { ... }

You take whatever template name you have and convert that to camelcase, eg basic-page = BasicPage, foo-bar = FooBar, home = Home and then you add the suffix Page to that name (FooBarPage, HomePage). In case of BasicPagePage it sounds a bit weird and I've myself done that wrong several times when I forgot the suffix and just called it BasicPage.php and wondered why it is not working. But once you get the concept it's easy and makes sense ? 

  • Like 2
  • 3 weeks later...
Posted

Damned, I have always thought that custom page classes were usable only in template.php files. ?‍♂️ This evening I wanted to hack PW to create a template/CustomPageClass mapping usable everywhere with PW API (get, find, etc), and in the first 3 minutes I found it was already there. ?

This is huge, I love it and am already refactoring some code and twig templates with a custom UserPage, using Traits to share some implementation with my RawUser class (an optimized class from direct database query). I'm quite excited! ?

  • Like 4
  • 1 year later...
Posted

Well, I kinda wish I knew about Page Classes sooner (sorry for the necrobump).  The method I'm using is to create my own class hierarchy and include the PW Page via composition (including a reference to the page).  So, processwire pages are purely backend, while the new classes encapsulate presentation and wrapping htmx features.  I'm likely duplicating a lot of work that ProcessWire can do for me!

I'm curious if anyone has any insight in possible other advantages and disadvantages of a composition approach rather than inheritance.

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...