8

I want to add an "Edit entry" button on each page for admin users. Am I overlooking a simple way to output the Edit link to the CP edit page for the current entry? Curious if there is something like {{ entry.editLink }}

2 Answers 2

23

There is! It's called cpEditUrl.

{% if currentUser %}
   {% if currentUser.isInGroup('admin') %}
       <a href="{{ entry.cpEditUrl }}">Edit entry</a>
   {% endif %}
{% endif %}

Or shorter (thanks to MISC):

{% if currentUser.admin %}
    <a href="{{ entry.cpEditUrl }}">Edit entry</a>
{% endif %}

Or forget user group altogether (thanks to Phil Gyford and bennobo):

{% if entry.isEditable() %}
    <a href="{{ entry.cpEditUrl }}">Edit entry</a>
{% endif %}
4
  • You are the man, Douglas!
    – taylor
    Commented Feb 10, 2015 at 23:33
  • 3
    Alternatively, you can use {% if entry.isEditable() %} as in this answer: craftcms.stackexchange.com/questions/130/… Commented Jul 9, 2015 at 12:56
  • 2
    Or even shorter: {% if currentUser.admin %}
    – MISC
    Commented Aug 2, 2015 at 6:50
  • 1
    I think that {% if entry.isEditable() %} is the way to go as it totally forgets the user/group logic. It's just one simple question: Can you edit?
    – bennobo
    Commented May 25, 2016 at 22:30
1

Here is Craft CMS 3 solution:

http://craftsnippets.com/articles/quick-edit

It works both with entries and categories and it takes multiple things into account while deciding if edit link should be displayed:

  • If the current user has access rights to control panel?
  • If the current user has rights to edit current entry/category?
  • If entry/category is not displayed through live preview?

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.