Show Link to Edit Entry
Problem
You want to expose a link to edit an entry, only showing the link if the logged-in user has permission to edit that Section’s entries.
Solution
{# somePage.html #}
{% include '_cpEditLink' with {
'thisEntry': entry
} %}
{# someEvent.html #}
{% include '_cpEditLink' with {
'thisEntry': entry,
'editText': 'Edit This Event'
} %}
{# _cpEditLink.html #}
{% if currentUser is not null %}
{% set sectionPermission = 'editEntries' ~ thisEntry.sectionId %}
{% if currentUser.can(sectionPermission) %}
<a href="{{ thisEntry.getCpEditUrl() }}" target="_blank" class="edit-this-page">
{{- (editText is defined) ? editText : 'Edit This Page' -}}
</a>
{% endif %}
{% endif %}
Submitted by Patrick Harrington on 1st February, 2017