Skip to content

Instantly share code, notes, and snippets.

@piotrpog
Last active December 3, 2023 15:59
Show Gist options
  • Save piotrpog/a2a03474783cf5d267bcd55095bd0a9c to your computer and use it in GitHub Desktop.
Save piotrpog/a2a03474783cf5d267bcd55095bd0a9c to your computer and use it in GitHub Desktop.
Quick edit link component for Craft CMS 3. More info on http://craftsnippets.com/articles/quick-edit
{# v4 #}
{% if currentUser and currentUser.can('accessCp') and not craft.app.request.isLivePreview %}
{% set element = element|default(craft.app.urlManager.matchedElement) %}
{% if element and element.isEditable %}
{% set editLink = element.getCpEditUrl() %}
{% if element.draftId is defined and element.draftId is not null %}
{% set editLink = editLink ~ '&draftId='~ element.draftId %}
{% endif %}
{% set editText = 'edit'|t %}
{% else %}
{% set editLink = cpUrl() %}
{% set editText = 'control panel'|t %}
{% endif %}
<aside class="cs-edit-link">
<a href="{{editLink}}" target="_blank" class="button is-info">{{editText}}</a>
</aside>
{% endif %}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment