Jump to content

Recommended Posts

Posted (edited)

I'm managing my users base with the built in users API. Some of the users are learners, some are teachers. I tag them with the roles property. Now, I would like to have in my webiste a section, let's call it 'teachers' whose children bear the same informations I put in the users pages. That is if I load /teachers/paul/ I see on that page users->get('paul')->allDataBlabla . 
Is there a way to automatize this process of displaying and if possible also creataing pages under the /teachers/ root page? Maybe intercepting the querystring and doing the logic on a 'teacher' page?

Thank you very much

Edited by Manaus
  • Manaus changed the title to Mirroring users data on another site section
Posted (edited)

If you were doing this you could just make user pages available whereever you want: https://processwire.com/blog/posts/processwire-core-updates-2.5.14/#multiple-templates-or-parents-for-users

Otherwise you could use UrlSegments or Path Hooks to load the requested user, such as:

//requesting /teachers/paul

$teacher = users()->get('roles=teacher, name=' . input()->urlSegment1); //urlsegments are already sanitized

if (!$teacher->id)
    throw new Wire404Exception();

echo $teacher->firstname . ' ' . $teacher->lastname;

 

Edited by Jan Romero
  • Like 2

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
  • Recently Browsing   0 members

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