Robin S Posted April 17, 2016 Share Posted April 17, 2016 My project has a page that I want to store archived versions of. This isn't for version control or anything like that - it's just a page that gets regularly updated and visitors should be able to browse the previous versions of it. So my idea is to have a page structure like this: My PageMy Page - 16 April 2016 My Page - 9 April 2016 My Page - 28 March 2016 The top "My Page" just pulls in the content from the most recent child page and then displays a list of links to all children but the most recent. To create a new version of the page an editor will create a new child of "My Page". But I don't want them to have to enter a page title - the title should always be "My Page - [creation date]". I hadn't had reason to use the "Name format for children" template option before and I thought it was going to be the solution. But now I see that it just sets the name and not the title of child pages. Which puzzles me a bit. Is this option mostly intended for if you change Title to be non-global and then remove it from the template? Wouldn't it be better if this option automatically set the title rather than the name and then derived the name from the title as per normal? Anyway, main question: is there something I can hook into to either Fill out the title field in the first step of the Add New page process (and ideally make it non-editable by the user) Or fill out the title field in the second step of the Add New page process. Then I can skip the first step via the "Name format for children" option and set the title field visibility to locked so it's not editable. This might be the better option. Link to comment Share on other sites More sharing options...
bernhard Posted April 17, 2016 Share Posted April 17, 2016 hi robin, as simple as this: (put it in your /site/ready.php file and adjust to your needs) $this->pages->addHookAfter('added', function($event) { $page = $event->arguments[0]; if($page->template != 'your-template-name') return; $page->setAndSave('title', 'my page - ' . date("YmdHis")); }); set page name format for children to something like Y/m/d H:i:s and set title to locked 6 Link to comment Share on other sites More sharing options...
kongondo Posted April 17, 2016 Share Posted April 17, 2016 Probably best to point out (to new users) that setAndSave() is a recent addition. Otherwise you might bet questions why is it not working for me? 3 Link to comment Share on other sites More sharing options...
bernhard Posted April 17, 2016 Share Posted April 17, 2016 you are right, though it would have to be either version 2.6.7 or 2.6.8 because before 2.6.7 there is no hooking via ready.php Link to comment Share on other sites More sharing options...
Robin S Posted April 17, 2016 Author Share Posted April 17, 2016 Many thanks! 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