Skip to content

Instantly share code, notes, and snippets.

@piotrpog piotrpog/quick_edit.twig
Last active Jul 6, 2019

Embed
What would you like to do?
Quick edit link component for Craft CMS. More info on http://craftsnippets.com/articles/quick-edit
{# v3 #}
{% 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() %}
{% set editText = 'edit'|t %}
{% else %}
{% set editLink = cpUrl() %}
{% set editText = 'control panel'|t %}
{% endif %}
<div class="edit-button">
<a href="{{editLink}}" target="_blank" class="button is-info">{{editText}}</a>
</div>
{% endif %}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.