Cms: Allow Users to have URLs like Entries

Created on 31 Jan 2017  路  9Comments  路  Source: craftcms/cms

Created by: David Ritter ([email protected]) on 2015/05/18 19:35:25 +0000
Votes at time of UserVoice import: 6


That way we wouldn鈥檛 have to work around ugly routing hacks to get author pages based on a username, for example. Instead it could be a user definable slug. That slug/URL format could even theoretically be different based on User Type/Group.

For example, in an e-commerce situation, Customers are users. You want to give them the ability to login, etc. Having that routing already built-in would be a clean way to handle it instead of trying to relate a customer to a separate entry.

* Live Preview *
If an author wants their own bio page, there鈥檚 no way Live Preview will work currently based on entries. Again, the workaround of course is to make a separate section for Authors, for example, but it seems that鈥檚 duplicating efforts. Now there鈥檚 permissions to worry about, relating things back, etc. Live Preview for an author鈥檚 page could automatically start working if it had an entry format.

enhancement site development

Most helpful comment

I could definitely use something like this. It would simplify a number of things if Users were treated just like Entry's and Category Groups, and thus had their own URLs, templates, and the User entry auto-injected into them.

In addition to unifying the model, this would allow things like sitemaps and meta generators to "just work" the way they do for Entry's and Category Groups.

The exact same UI could be used for this as is used for Sections and Category groups "Users have their own URLs" and Site uri/template assignments.

All 9 comments

Glancing at the DB architecture, it seems like things are already kinda set up for this!

@lindseydiloreto nice! This would be great. Feels weird to thumb up my own feature suggestion but hey it's not facebook so it's all good!

I could definitely use something like this. It would simplify a number of things if Users were treated just like Entry's and Category Groups, and thus had their own URLs, templates, and the User entry auto-injected into them.

In addition to unifying the model, this would allow things like sitemaps and meta generators to "just work" the way they do for Entry's and Category Groups.

The exact same UI could be used for this as is used for Sections and Category groups "Users have their own URLs" and Site uri/template assignments.

This would solve https://github.com/craftcms/cms/issues/3308 as well

Hoping for this one in 2019!

@RitterKnightCreative How would you see routing/URL formatting work on a per user group basis? Unlike sections and category groups - a user can be assigned to multiple user groups so you would need some way to prevent those collisions. Do you have an example for when this would be required as opposed to just a global site-by-site determination?

@gtettelaar Good question.

As @khalwat mentions above, users could simply get their own URLs (or not). Not sure if we need to factor user groups in. Maybe a lightswitch for if the user is "public" or not? If they are, they get routed.

I think this would solve most use cases since you can route the rest if needed since users now have slugs.

A slightly cleaner but more complicated solution might be when we first set up a new user group, maybe we could elect to have a URL structure as well with the group... similar to how we set up a category group? Any user that's in that group gets routed, if not we fall back to what we do now.

The only issue there would be which template do you load for a live preview for a user if a user is in more than one group... I suppose a checkbox for "Use this group for live preview." or something.

@RitterKnightCreative Im working on implementing this alongside #1058 for the RC3/RC4 release next week. The question I had was more regarding how much you would _need_:

That slug/URL format could even theoretically be different based on User Type/Group

In my _current_ implementation, you go to /admin/settings/users/settings and you will be presented with a familiar looking table field: https://i.imgur.com/2L6nzsP.png

In the backend, whenever you save a user, a URL according to those formats will be stored, unique to the user. Once that URL gets hit on the frontend, the template you entered will be rendered, all site-specific ofc.

Basically, it's Craft's native routing - exactly the same as categories/entries - only for users, we determine the template and URI format globally. If you ever need different URL's for user's that vary whether a user is in Group A or Group B - I doubt that's something Craft can support natively.

You can of course still manually route them AND use the slug to support whatever routing config u need.

Perhaps it's worth revisiting this once the PR is live - I'll post an update here and then you can test it locally to see if you are missing anything.

p.s.
Once the fork gets merged Users will also have LivePreview + each field will be localizable in exactly the same way as Entries and Categories #1058.

@gtettelaar Sweet - that'll work great IMO.

TBH I'm not entirely sure how much I'd actually really user type/groups in the URL... I know I wrote that in the original feature suggestion but most of the time, we just end up with one user route. Of course, would be interesting to hear from others though!

@RitterKnightCreative Just an f.y.i, I got around to implementing a proposal for this early. See https://github.com/craftcms/cms/pull/4463.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

bitboxfw picture bitboxfw  路  3Comments

brandonkelly picture brandonkelly  路  3Comments

angrybrad picture angrybrad  路  3Comments

leigeber picture leigeber  路  3Comments

davist11 picture davist11  路  3Comments