Jump to content

Creating a page without a title?


deane.barker
 Share

Recommended Posts

I have a "Person" template, with fields for FirstName and LastName. There is no need for this page to have a "Title" because the title should always be "LastName, FirstName".

I have successfully created the hook to do this -- when you publish, the Title of the page is set to "LastName, FirstName" and the page is saved. Then I hid the Title field on the Edit Page screen.

However, PW still requires that you Title the page when you first create it. So, you are asked to enter a Title, URL segment, and select a template.

Is it possible to suppress the Title field on the Add New screen? I think this is going to be hard, because on that screen, you haven't even picked a template yet, so PW has no way of knowing you're creating a Person and should therefore not enter a Title.

This is a specific example of a more general problem -- when the Title of a page should be formed from structured data found in the template definition, how do you handle the apparent need for an editor to enter a Title which will immediately be reset? This is a training issue -- you could explain this to editors, but they'll find it confusing ("So...when do I enter a title? On this one? Why not on this one?").

post-806-0-73386600-1352408955_thumb.png

  • Like 1
Link to comment
Share on other sites

Hello Deane, welcome to the PW forum.

This question (well, one very similar) came up recently in the forum. Basically it's because the title field is setup as a global field and is therefore needed in every template. To cure it, please try...

  1. setup > fields > title > advanced tab > turn off the global flag > save.
  2. setup > templates > basic-page (or whichever template doesn't need a title) > delete the title field > save

And enjoy ProcessWire! :)

Link to comment
Share on other sites

ProcessWire requires to have the title and name field for every page. If you remove the title you need to turn off global setting of the title field and remove it from the template you wish, BUT this will result in every page you create not having a title field. Technically I think it only needs the name field at the least. So this might be not a problem, as you could see "name" field like a filename when you create a file.

However you could also

1.) setup a template "persons" and make it only allow children pages of the "person" template. (In the family tab you can select allowed children templates.)

2.) In the person template you click on the "title" field and it will open an dialog editor to edit the field attributes in context to the person template, enter "Name" instead of "Title" in the label field and save.

3.) Then if you ceate a new child page under the page with the "persons" template, it will show the title field labled as "Name".

Link to comment
Share on other sites

I don't know 100% for sure as I haven't dug that deeply into the code. However, I'd guess it goes like this: 'as global' fields are needed in every PW page, PW can collect it before you choose the template. If a field isn't global, the collection will have to get pushed back till after you choose the template.

Link to comment
Share on other sites

While you can un-global that title field (which I don't think I've personally done), I think it's not a bad idea to keep it around as a standard when possible. I've setup things like you are talking about before (company directory), and I'll usually re-purpose the title field on the "person" template to contain the "full name" or "last name". You can change the labels for the fields so that it identifies itself as something else by changing the field context in the template editor. You might also want to make use of the template "family" settings to define that when adding a page to say /company-directory/ it will only accept children using your "person" template. That way you aren't selecting a template when adding a page there.

  • Like 1
Link to comment
Share on other sites

Hi Deane and welcome to the forums.

I have never removed the title myself, so not sure how pw behaves on this situation. But take a look at the "family" tab on template settings. It will allow you to choose that template "people" can only have pages with template "person". This way when you add pages under "people", those will be automatically "person" and no template dropdown is shown.

Now that I took a look my person templates (usually actual users, since those are pages too), I use title always as a "fullname", and have separate fields for Firstname and Lastname. Maybe you could do a hook other way: parse firstname and lastname values from the title?

Tip: you can edit the title label and description on per template basis: so title label can actually be a "Full Name" on person templates - and you can also put a description like "Write lastname first, ie. Meikäläinen, Matti"

EDIT: I'm way too slow :)

Link to comment
Share on other sites

The problem with removing the Title field is that this leaves the Add New page in a weird state -- no Title, but a Name field (the URL segment). Since there's no Title, the Name doesn't get set automatically, so you're asking someone to input a raw URL segment (without one being suggested).

It looks odd, to say the least.

  • Like 1
Link to comment
Share on other sites

Man you guys are fast, you beat me to it. :)

Anyway, I think having a global "title" field is a good idea, just from the standpoint of having something that is consistent on all your pages. This greatly simplifies your job when creating something like a site-wide search engine, for instance. I also like my "title" field to play the role of the HTML <title> tag. For the same reason, I often have a global "summary" field that is also useful when creating site-wide search engines, and meta descriptions.

  • Like 2
Link to comment
Share on other sites

I think having a global "title" field is a good idea, just from the standpoint of having something that is consistent on all your pages. This greatly simplifies your job when creating something like a site-wide search engine, for instance.

I agree. The Title field will exist, but I will set it automatically every time the page is published. Behind the scenes, the data will be there. I just need the user to not have to set it.

  • Like 1
Link to comment
Share on other sites

It looks odd, to say the least.

ProcessWire considers the 'name' a very important component of a page (perhaps the most important). This is what people see in the URL and how the page is represented to the outside world.

The reason you have to create a page before you start populating it is because we don't really know what fields we'll be dealing with in the page editor. Some fieldtypes require that a page has a dedicated place to store files, especially with ajax uploads, for instance. Some fieldtypes like repeaters need to know the page's ID. We want to keep things predictable for Fieldtype/Inputfield module developers, so want to make sure they've got a tangible page to work with. The page "name" is all that we really need to know in order to create a page. A page's name (and thereby URL) play a big role in ProcessWire. It's the primary means of a page's identification, as well as source of the path/URL. In order to ensure uniqueness in any path, the 'name' (under a given parent) is enforced as unique at the DB schema level. For all these reasons, you have to choose a name to create a page, and it's supposed to be a good thing.

The Title field will exist, but I will set it automatically every time the page is published. Behind the scenes, the data will be there. I just need the user to not have to set it.

This is a different approach than I've seen before, but can't think of any reason why it wouldn't work. However, I do think life might be simpler just to re-purpose it since PW lets you change field context by template. If you are building a company directory, and don't want to have a "full name" field, something like "job title" might be a good one (it even has the word 'title' in it). :)

  • Like 1
Link to comment
Share on other sites

ProcessWire considers the 'name' a very important component of a page (perhaps the most important).

Yeah, I totally get this. I just want to set Name and Title automatically. I want to find a way to hide both these fields, and set these to arbitrary values if no value was entered (set them to the page ID, for instance).

What would be helpful is not to require any validation on these fields, behind-the-scenes. When you save a page, if they have not been set, set them to the page ID. Setting them can still be enforced by validation on the UI, but have a failsafe so that the UI can be altered and pages still save just fine.

I could probably do this client-side with some Javascript. If they select "Person" from the dropdown, disable both fields then, when the form is submitted, set them to random values. Then, hook the post-save event, and reset them to the page ID, after which they'll be managed automatically.

But, we're wandering down the hack rabbit hole pretty quickly here...

  • Like 1
Link to comment
Share on other sites

I think it'd be feasible to make such an option available. I'm not at a place where I can check the code, but I think this may be how we have the API set (default to the 'id' as name when no name set). So it'll most likely be fairly simple front-end stuff to make it support that. I'll experiment on the dev branch here to see what we could implement.

Link to comment
Share on other sites

My solution is ugly, but it works.

Just inside Pages->__save

if($page->name == '') {
$page->name = 'temp' . microtime();
}

Then towards the bottom of that function, just before the hooks are run:

if(substr($page->name,0,4) == 'temp') {
$page->name = $page->id;
$page->title = $page->id;
$this->save($page, $options);
}

Obviously, this needs to be made quite a bit more robust (the string "temp" is collision-prone as hell), but the theory works. In general.

  1. Set a random-ish temporary name, with a detectable pattern (starting with "temp" in this case)
  2. Insert (to get an ID)
  3. After the Insert, if the name matches the temporary name pattern, set name and title to the ID and re-save.
Link to comment
Share on other sites

Okay, I must be confusing with a PW1 behavior, which I still do when I don't have the code in front of me. But I can say it's definitely feasible. Probably need to assign a random name on first save, before changing it to id since id wouldn't be known prior to save. Name is a unique key (when combined with parent id) so don't think it can be undefined.

Link to comment
Share on other sites

Okay, I found it. I had to comment out a half-dozen lines in that ProcessPageAdd module, but it all works fine.

I would love to do this without hacking the core, obviously. To do this, I'd need hooks immediately before database insert, then again after, I think.

Although, with a little more work, the code would be fairly innocuous and could be included in the core -- it would never trigger on a default install since the "Name" field would always be shown and validated, and therefore always contain a value. For the code to ever execute, you need to save a page with no name, and that couldn't happen unless you deliberately messed around with the Add New screen to remove the "Name" field.

Link to comment
Share on other sites

I'm only half following this, but could this mean that eventually adding a page isn't a two-screen process?

If the page is just assigned an ID to start with and the name field is the same as the ID (or something like "page-ID" so you know someone's not actually trying to call the name as the ID on purpose) then it could actually set the name field correctly on the next screen with the rest of the fields once you enter a title.

So in pseudo-code: if name == page-{ID} and title != '' then name = sanitize(title)

Did that make any sense Ryan? I'm only thinking this because I have found that a few people have asked why creating a page is a two step process. Whilst this is done for reasons outlined in this thread and elsewhere, it would be nice to have an option to make it a one-step process if that's where this conversation might be headed. (Not suggesting that those people found it difficult to use a two-step process as there is currently of course - once you explain it it's pretty straightforward).

Of course the biggest pitfall for this is if someone then clicks off the page without saving then they have a page with no title and a name of "page-ID".

Link to comment
Share on other sites

IMO it open some inconsistency with the system I don't like. I like the way it is and client should deal with it and it should always be same, that's why PW is so great. I'm personally not keen with having possibility to change the process to different behaviors and inconsistency throughout the system.

There a simple approach as we mentioned with template family settings and field template context which is a good thing.

Link to comment
Share on other sites

If you're automatically setting the name and title, and there's only one template that can be used, then, yes, it should be a one-step process.

We work with another CMS which is architecturally very similar to PW. If you cannot select a content type for that spot (meaning there's only one that can be used), then you go directly to the editing form without the "pick a content type" screen in between. Editors understand it just fine.

  • Like 1
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...