7

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
  • To my knowledge, there is no built in user routing. What exactly are you trying to achieve? Are you wanting to display a profile of a staff member or user at the url (i.e. /profile/{{ username }} )?
    – Ryan Shrum
    Commented Jul 21, 2014 at 22:27
  • Yes, I'm trying to display profile pages for users in the system. Commented Jul 22, 2014 at 15:29

2 Answers 2

16

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 %}
  1. Craft Admin › Settings › Routes
  2. New Route
  3. If the URI looks like this: profile/* (Use the * token provided)
  4. 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 }} ).

0
7

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.

2
  • 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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.