One of the very few things I miss from WordPress is the ability to jump straight from viewing a page to editing the content. Turns out 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 page.link == '/' %}
{% set editPagePath = "/" ~ page.slug %}
{% else %}
{% set editPagePath = uri.path %}
{% endif %}
<a class="editpage" href="/admin/pages{{ editPagePath }}">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):