Jump to content

Automatic name and title?


tires
 Share

Recommended Posts

Is there a way to automatically create the title and the name of a page from the content of two fields?
I have the problem that the editor usually has to enter the same thing in the title field as in these two fields.

What is the easiest way? Or is there perhaps a module?

Link to comment
Share on other sites

You can use FieldtypeConcat, or do it with a hook.

https://processwire.com/modules/fieldtype-concat/

 

	// Merge First and Surname for Title and Name
	if($page->template == 'some-template') {
		// Don't change name field if page is going to trash
		if(!$page->isTrash) {
			// If the fields that make up the title are populated
			if($page->first_name && $page->surname) {
				// Set the title
				$page->title = "{$page->first_name} {$page->surname}";
				// Sanitize the title as a page name
				$name = $event->wire()->sanitizer->pageName($page->title, true);
				// Set the page name while making sure it auto-increments if there is a sibling page with the same title
				$page->name = $pages->names()->uniquePageName($name, $page);
			}
		}
	}

 

  • Like 2
Link to comment
Share on other sites

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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...