2

How would one go about showing a link on the front end if this entry belongs to the current user? I was thinking it had something to do with the UserModel's can(), but I don't see any documentation of it.

Right now I'm showing an "Edit Page" link once someone is logged in, but I don't want to show a that link on a page that the current user doesn't have access to edit.

Any thoughts on this?

Edit

I was hoping something like this would work but it doesn't :( :

{% if entry.author == currentUser %}
    <a class="btn btn-primary btn-small cp" href="{{ entry.getCpEditUrl() }}">Edit Page</a>
{% endif %}
4

You can check if the current user can edit an entry by using this as your conditional:

{% if entry.isEditable() %}
    <a href="{{ entry.cpEditUrl }}">Edit Page</a>
{% endif %}
  • Does that work when adding that to your Base layout? I'm running the conditional in my base layout and it's not showing the link although the current author owns the page I'm testing. – Mark Busnelli Jr Jun 13 '14 at 16:05
  • If you can access the entry model, then it should work fine. If you're adding it to the layout as opposed to the template you may be running into a scope issue. Try creating a {% block %} where the link should be and add the above code in the template under the newly created block. – Bryan Redeagle Jun 13 '14 at 16:09
  • Hmmm that's not working for me on the front end. Is there something that I can do something with {% if currentUser.can('permission') %} ... {% endif %} ? I just don't know, nor can I find what can() can do :) I found .can('createEntries:5') but curious if there's a rendition of .can('editEntries:5') or something. – Mark Busnelli Jr Jun 13 '14 at 16:28
  • The above should work. I would need to know way more before I could tell you why it's not. The function is really just a shortcut for a permission check. The one you're looking for is .can('publishEntries:5'). With 5 being the section id. – Bryan Redeagle Jun 13 '14 at 17:26

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.