Add 'Edit' button to page

WordPress has a useful feature that allows you to jump straight from viewing a page to editing the content. This is very easy to get working with Grav.

First, in System Configuration, set the session split option to “no”.


This will mean you log in to both front and back end simultaneously.

Now add this code to base.html.twig

{% if config.plugins.admin.enabled and authorize(['admin.pages', 'admin.super']) %}
   {% if == '/' %}
     {% set editPagePath = "/" ~ page.slug %}
   {% else %}
     {% set editPagePath = uri.path %}
   {% endif %}
   <a class="editpage" href="{{ adminPath }}{{ editPagePath }}" target="_blank">Edit</a>
 {% endif %}

and you can style it by adding some code to css, for example:

.editpage {
  position: fixed;
  top: 0;
  right: 0;
  padding: 5px 10px 4px 10px;
  background: #023A71;
  color: #fff;
  display: block;
  font-weight: bold;
  text-decoration: none;
  border: none;
  text-transform: uppercase;
a.editpage:hover {
  color: #dadde1;

The result should look like this (I have also removed the login item from the menu):