TomPich Posted May 6, 2024 Share Posted May 6, 2024 Hi guys, I think what I try to achieve is quite simple, nevertheless I can’t find out how to do it. On a specific template, I’d like to add some general description about the whole template. It’s just some text that I’d like to insert at the beginning of the admin page when a page based on this template is edited. I don’t need to create a whole new custom admin page. Any clue? Thanks Link to comment Share on other sites More sharing options...
Nicolas Posted May 6, 2024 Share Posted May 6, 2024 Hi, Using ProcessWire notice system you could do something like <?php // In /site/ready.php $wire->addHookAfter('ProcessPageEdit::execute', function (HookEvent $event) { $pageEdit = $event->object; $page = $pageEdit->getPage(); if ($page->template == 'home') { $this->wire('notices')->add(new NoticeMessage("Hello World")); } }); 3 1 Link to comment Share on other sites More sharing options...
netcarver Posted May 6, 2024 Share Posted May 6, 2024 In addition to the great suggestion from @Nicolas, you can also do it by prepending a Markup textfield to the edit form for just that particular template. Here's more code - I'd put this in site/templates/admin.php as this is only an admin feature. $pages->addHookAfter("ProcessPageEdit::buildForm", function($event) { $form = $event->return; $id = (int) wire("input")->get("id"); if (!$id) { return; } $editedPage = wire("pages")->get($id); if ($editedPage->template->name === "home") { // CHANGE TEMPLATE NAME HERE $f = wire()->modules->get('InputfieldMarkup'); $f->label = "Notes"; $f->value = "<p>Your HTML Notes in here.</p>"; $form->prepend($f); } }); 3 1 Link to comment Share on other sites More sharing options...
bernhard Posted May 6, 2024 Share Posted May 6, 2024 Or when using Custom Page Classes + MagicPages you have your code where it belongs (if it's for the "home" template then it's in the HomePage.php file) and avoid hook hell in site/ready.php // site/classes/HomePage.php class HomePage extends DefaultPage { use MagicPage; public function editForm($form): void { $f = new InputfieldMarkup(); $f->label = 'Help'; $f->value = 'Foo bar baz!'; $form->prepend($f); } } 3 1 Link to comment Share on other sites More sharing options...
virtualgadjo Posted May 6, 2024 Share Posted May 6, 2024 Hi, honestly for this kind of thing i use one of those two modules ? https://processwire.com/search/?q=runtime&t=Modules Robin's one is a little more recent but both work fine have a nice day 3 1 Link to comment Share on other sites More sharing options...
Nicolas Posted May 6, 2024 Share Posted May 6, 2024 @virtualgadjo I might compare ProcessWire to the Perl language : "There is more than one way to do it" ©. Thanks to ProcessWire flexibility, it's good to have options depending on the way one is more comfortable with. 1 Link to comment Share on other sites More sharing options...
virtualgadjo Posted May 6, 2024 Share Posted May 6, 2024 @Nicolas you're right and it's one of those things that makes it so great without speaking of all those crazy guys here who never stop helping while writing great addons ? 2 Link to comment Share on other sites More sharing options...
TomPich Posted May 7, 2024 Author Share Posted May 7, 2024 Thank you guys. You are amazing. I prefer not to use modules when what I want can be achieved with a few lines (this is an old habit I got with WordMessPress). I’ll try your suggestions. And I’ll investigate about this MagicPage. I read this name three times yesterday and I have no clue about what it is. 2 Link to comment Share on other sites More sharing options...
gebeer Posted May 7, 2024 Share Posted May 7, 2024 5 hours ago, TomPich said: And I’ll investigate about this MagicPage. I read this name three times yesterday and I have no clue about what it is. Here you go: https://www.baumrock.com/en/processwire/modules/rockmigrations/docs/magicpages/ 1 1 Link to comment Share on other sites More sharing options...
TomPich Posted May 7, 2024 Author Share Posted May 7, 2024 Thanks @gebeer This RockMigration module seems really interesting. 2 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