cb2004 Posted January 5, 2016 Posted January 5, 2016 So if I am editing a page and it has children, can I display a text box? Cheers.
bernhard Posted January 5, 2016 Posted January 5, 2016 this in your /site/ready.php <?php $wire->addHookAfter("ProcessPageEdit::buildForm", function(HookEvent $event){ $process = $event->object; $form = $event->return; $page = $process->getPage(); // remove field when actual page has no children if($page->numChildren == 0) { $form->remove($form->getChildByName('your_field_name')); } }); 2
cb2004 Posted January 5, 2016 Author Posted January 5, 2016 (edited) Cheers BernhardB, no joy I am afraid though. Edit: scrap that, I enabled debug mode and then all was fine. Thanks. Edited January 5, 2016 by cb2004
bernhard Posted January 5, 2016 Posted January 5, 2016 So if I am editing a page and it has children, can I display a text box? Cheers. what do you exactly mean by "text box" ? Cheers BernhardB, no joy I am afraid though. ?
cb2004 Posted January 5, 2016 Author Posted January 5, 2016 It works fine, cheers (edited my above post). Where can I read up more about hooks?
bernhard Posted January 5, 2016 Posted January 5, 2016 hi cb2004, glad it worked. 1) google https://www.google.at/search?q=site:processwire.com+hooks&gws_rd=cr&ei=IzeMVuCqMYSnU7jZuIAK 2) the helloworld module https://github.com/ryancramerdesign/ProcessWire/blob/master/site-default/modules/Helloworld.module 3) blog (especially for my suggested way of using ready.php) https://processwire.com/blog/posts/processwire-2.6.7-core-updates-and-more/ i recommend reading the blog regularly - that's a great place to learn 4) go through the modules directory and see how others do it. start with simple modules and then go further. and one day you will have to dive into the "wire" folder have fun
cb2004 Posted January 5, 2016 Author Posted January 5, 2016 Yeah I jumped into the blog post shortly after and came up with the following: <?php $pages->addHookAfter("ProcessPageEdit::buildForm", function($event) { $form = $event->return; $page = $event->object; if ($page->template->id == 47 && $page->numChildren == 0) { $form->remove($form->getChildByName("rte_basic_2")); } }); 1
kongondo Posted January 6, 2016 Posted January 6, 2016 It works fine, cheers (edited my above post). Where can I read up more about hooks? All About ProcessWire Hooks http://processwire.com/api/hooks/
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