Grav-plugin-admin: Frontend "Edit" link

Created on 21 Nov 2016  ·  9Comments  ·  Source: getgrav/grav-plugin-admin

Is there a way I can add a simple "Edit" link on all frontend pages. This link would need to check if the grav-plugin-admin plugin is installed and the user has the correct permissions.

question

Most helpful comment

Thanks for the help everyone. Maybe there is a better way to do it, but here is what I ended up doing in my partials/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 then in my css

.editpage {
  position: fixed;
  bottom: 0;
  right: 0;
  padding: 5px 6px;
  background: #F67E40;
  color: #fff;
  display: block;
  font-weight: bold;
  text-decoration: none;
  text-transform: uppercase;
}

It would be nice if something like this was included by default in all the themes.

Maybe the admin plugin could include a page variable for the edit link? It would look a lot nicer in templates than the code I provided.

All 9 comments

This can be implemented in your theme directly, so you already know the admin plugin is installed, you can wrap the link in a {% if authorize(['admin.pages', 'admin.super']) %} conditional

Hi @flaviocopes , I've been following this thread and am looking to do something quite similar: trigger a Grav login screen when a button is pressed and if logged in successfully run some Twig code. Is this also possible, and if so is there an existing example for me to learn from? Thank you!

Never mind @flaviocopes , someone just pointed me to this little gem: https://learn.getgrav.org/cookbook/general-recipes#create-a-private-area 🙂

Thanks @flaviocopes. I tried adding
{% if authorize(['admin.pages', 'admin.super']) %} <a href="#">Edit</a> {% endif%}

to my base.html.twig, but it didn't work. I cleared the cache and logged in and then checked my page, but no Edit link was printed to the page.

Any other ideas? Something like this should probably be in a core theme like Antimatter to make it easier for editors to quickly jump to the admin to edit the page?

You will need to be logged in to the frontend with an admin user. Being logged into the admin is not enough by default as the admin and frontend sessions are separate.

@rhukster . I logged into the /admin using the site admin login(that's the only user). How do I login to frontend? Sorry, I'm new to Grav.

Use the Login plugin, see the readme on https://github.com/getgrav/grav-plugin-login (https://github.com/getgrav/grav-plugin-login#login-page)

Closing as the question is answered

Thanks for the help everyone. Maybe there is a better way to do it, but here is what I ended up doing in my partials/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 then in my css

.editpage {
  position: fixed;
  bottom: 0;
  right: 0;
  padding: 5px 6px;
  background: #F67E40;
  color: #fff;
  display: block;
  font-weight: bold;
  text-decoration: none;
  text-transform: uppercase;
}

It would be nice if something like this was included by default in all the themes.

Maybe the admin plugin could include a page variable for the edit link? It would look a lot nicer in templates than the code I provided.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

wildafrica picture wildafrica  ·  4Comments

darkroastcreative picture darkroastcreative  ·  4Comments

fourroses666 picture fourroses666  ·  4Comments

ritchiedalto picture ritchiedalto  ·  6Comments

danzinger picture danzinger  ·  5Comments