1

I am trying to create a link that would allow a logged in user to access their profile from the front end. Basically, the user has one page they can edit from the front end when logged in, and I'd like to link to that page in the navigation. I've seen similar things done in Craft 2 but not in Craft 3. So far I tried this: but it didn't work.

{% set myEntry = craft.entries.section('userProfiles').authorId(currentUser.id).limit(1) %}
<a href="{{ userProfiles.url() }}">My Profile</a>

as well as..

{{ myEntry.limit(1).url() }}

Thank you!

1

You need to fetch the entry with one() keep in mind in order to be able to be an author the user needs the permission to create entries in that section

{% set myEntry = craft.entries.section('userProfiles').authorId(currentUser.id).one() %} 
<a href="{{ myEntry.getUrl() }}">My Profile</a>

You should also consider to code defensively and check if there is a current user and if myEntry is not null

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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