Skip to content

Instantly share code, notes, and snippets.

@samhernandez
Created September 3, 2014 16:38
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save samhernandez/bc0516fa4b8e8151606f to your computer and use it in GitHub Desktop.
Save samhernandez/bc0516fa4b8e8151606f to your computer and use it in GitHub Desktop.
Craft CMS edit entry link
{% if entry is defined and currentUser and currentUser.can('editEntries:' ~ entry.id) %}
<a href="{{ entry.cpEditUrl }}" class="edit-this section-{{ entry.sectionId }}">Edit this</a>
{% endif %}
@samhernandez
Copy link
Author

Put this file in a partials folder and include it wherever you need an edit link.

Example _entry.html:

{% extends "_layout" %}

{% block content %}
  <article>
    <h1>{{ entry.title }}</h1>
    {{ include 'partials/edit-this' }}
    <p>Posted on {{ entry.postDate.format('F d, Y') }}</p>
    {{ entry.body }}
  </article>
{% endblock %}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment