johnstephens Posted November 10, 2020 Share Posted November 10, 2020 Hi! I'm using ProcessWire's ability to recognize custom Page classes, and I have added some very useful methods to my DefaultPage class. I just tried using one of the methods on a Repeater field item and got the error saying, "Method RepeaterPage::meta_description does not exist or is not callable in this context". Makes sense! My method is attached to DefaultPage, not RepeaterPage. That surfaces two questions: How do I extend RepeaterPage? By creating a DefaultRepeaterPage.php file in the /site/classes directory? What is the proper way to abstract methods that I want to use for both DefaultPage and RepeaterPage, so I don't have to repeat the same code in both classes? I think I understand how to do it if they both extended the same parent class, but I don't see how that can be the case here. Thank you in advance! 2 Link to comment Share on other sites More sharing options...
johnstephens Posted November 10, 2020 Author Share Posted November 10, 2020 I have a third question that is unrelated to this problem: How do I associate a new custom Page class with a template in ProcessWire, if the template doesn't have a template file (because it is used in other templates)? Link to comment Share on other sites More sharing options...
elabx Posted November 10, 2020 Share Posted November 10, 2020 15 minutes ago, johnstephens said: What is the proper way to abstract methods that I want to use for both DefaultPage and RepeaterPage, so I don't have to repeat the same code in both classes? I think I understand how to do it if they both extended the same parent class, but I don't see how that can be the case here. Not sure if "the most proper" but one way I can think of is creating a module that adds the required methods/properties through hooks and just reuse the same method for both hooks. 1 Link to comment Share on other sites More sharing options...
johnstephens Posted November 10, 2020 Author Share Posted November 10, 2020 Thanks, @elabx! Perhaps module development is the next step on my ProcessWire education path. I hope I can figure out extending RepeaterPage first. ? Link to comment Share on other sites More sharing options...
elabx Posted November 10, 2020 Share Posted November 10, 2020 3 minutes ago, johnstephens said: I hope I can figure out extending RepeaterPage first. ? I hope someone could shine some light if something like this is possible (don't know if you tried it?): CustomRepeaterPage extends RepeaterPage { ... } What I do a lot is on site/ready.php $wire->addHookMethod("RepeaterPage:newMethod", function(){ .. }) 2 Link to comment Share on other sites More sharing options...
johnstephens Posted November 11, 2020 Author Share Posted November 11, 2020 20 hours ago, elabx said: I hope someone could shine some light if something like this is possible (don't know if you tried it?): class CustomRepeaterPage extends RepeaterPage { /* … */ } I tried that, and I tried DefaultRepeaterPage too, placing them both in the /site/classes directory like my custom DefaultPage class which works. Alas, calling my Repeater field content still instantiates ProcessWire\RepeaterPage. I may try your addHookMethod() suggestion shortly. Thanks for the tip! Link to comment Share on other sites More sharing options...
thetuningspoon Posted October 3, 2023 Share Posted October 3, 2023 There is a workaround if you're willing to edit the core: https://github.com/processwire/processwire-requests/issues/239 2 Link to comment Share on other sites More sharing options...
bernhard Posted February 12 Share Posted February 12 Reference to the new feature: 1 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now