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 }}
Asked
Active
Viewed 3,752 times
8
2 Answers
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 %}
Douglas McDonald
- 13,457
- 24
- 57
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?
Piotr Pogorzelski
- 1,286
- 7
- 18
{% if entry.isEditable() %}as in this answer: http://craftcms.stackexchange.com/questions/130/how-can-i-grant-front-end-access-to-an-entry-that-belongs-to-the-current-user – Phil Gyford Jul 09 '15 at 12:56{% 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 May 25 '16 at 22:30