I'd like to manage my users (both active site users, and other employees at my client's company) via the Craft user management. I've added more profile fields, etc. But i'm wondering, is there a built in public profile page/route for users? I'm listing various users on a page, and i'd like their profile image to link to a profile page for each of them, with more info, contact info etc. What's the best way to do this?
2 Answers
You will need to add a custom route for the path for which you want to show the profile from a list of all users.
Per my example of /profile/{{ username }}
:
In your profile/index
template, you would run a loop on the user set of your choice:
{% set users = craft.users %}
{% for user in users %}
<a href="/profile/{{ user }}">{{ user }}</a>
{% endfor %}
- Craft Admin › Settings › Routes
- New Route
- If the URI looks like this:
profile/*
(Use the*
token provided) - Load this template:
profile/_profile
Then, in your profile/_profile
template,
{% set user = craft.users.username( craft.request.segment(2) ).first() %}
Once user
is defined, you can use the UserModel to return any data from that user (i.e. {{ user.email }}
).
If you simply need a public profile page, you can build that easy enough. Simply pass in some user identifier through the URI /profile/username
or /profile/userId
will do.
Then from your template:
{% set userId = craft.request.getSegment(2) %}
{% set user = craft.users.id(userId).first() %}
Now user
is a UserModel and you can access any of those properties of it as well as any custom fields you've assigned to users.
Additionally, you can create templates on the front-end for user management.
This includes public registration, editing user profiles, password reseting and logging in.
-
i don't need front-end user management, just want to be able to have a public profile page for each user in the system. Commented Jul 22, 2014 at 15:36
-
1@user412 Brad did show you how to do the basis of that very easily. You just need to write your template to access the user profile fields you want from 'user'. The rest is optional, if quite helpful to see how to do it ...from one of the founders of Craft. Commented Jul 23, 2014 at 4:57
/profile/{{ username }}
)?