Last active
December 10, 2023 00:45
-
-
Save piotrpog/810672df6c06354050c0f1b00363a360 to your computer and use it in GitHub Desktop.
Quick edit link component for Craft CMS 4. More info on http://craftsnippets.com/articles/quick-edit
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{# v5 #} | |
{% if currentUser and currentUser.can('accessCp') and not craft.app.request.isLivePreview %} | |
{% if _globals.get('currentElement') %} | |
{% set element = _globals.get('currentElement') %} | |
{% else %} | |
{% set element = craft.app.urlManager.matchedElement %} | |
{% endif %} | |
{% if element and element.canSave(currentUser) and element.getCpEditUrl() is not null %} | |
{% set editLink = element.getCpEditUrl() %} | |
{% set editText = 'edit'|t %} | |
{% else %} | |
{% set editLink = cpUrl() %} | |
{% set editText = 'control panel'|t %} | |
{% endif %} | |
{% tag 'aside' with { | |
style: { | |
'position': 'fixed', | |
'bottom': '3rem', | |
'right': '1rem', | |
'z-index': 9999 | |
}, | |
} %} | |
{% tag 'a' with { | |
href: editLink, | |
target: '_blank', | |
class: 'quick-edit__link', | |
style: { | |
'padding': '0.3rem 0.6rem', | |
'background-color': 'white', | |
'display': 'inline-block', | |
'box-shadow': '5px 5px 30px 0px rgb(171, 173, 202)', | |
'border-radius': '3px' | |
} | |
} %} | |
{{ editText }} | |
{% endtag %} | |
{% endtag %} | |
{% endif %} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment