Grav-plugin-admin: 前端“编辑”链接

创建于 2016-11-21  ·  9评论  ·  资料来源: getgrav/grav-plugin-admin

有没有一种方法可以在所有前端页面上添加简单的“编辑”链接。 该链接需要检查是否安装了grav-plugin-admin插件,并且用户具有正确的权限。

question

最有用的评论

感谢大家的帮助。 也许有更好的方法可以做到这一点,但这就是我最终在我的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 %}

然后在我的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;
}

如果所有主题默认都包含这样的内容,那就太好了。

也许管理插件可以包含用于编辑链接的页面变量? 模板中的代码看起来比我提供的代码好得多。

所有9条评论

这可以直接在您的主题中实现,因此您已经知道已安装了admin插件,可以将链接包装在{% if authorize(['admin.pages', 'admin.super']) %}有条件的环境中

@flaviocopes ,您好,我一直在关注该线程,并且希望做类似的事情:按下按钮时触发Grav登录屏幕,如果登录成功,则运行一些Twig代码。 这也是可能的,如果是这样,是否有可供我学习的现有示例? 谢谢!

没关系@flaviocopes ,有人只是将我指向了这个小宝石: https ://learn.getgrav.org/cookbook/general-recipes#create -a-private-area🙂

谢谢@flaviocopes。 我尝试添加
{% if authorize(['admin.pages', 'admin.super']) %} <a href="#">Edit</a> {% endif%}

到我的base.html.twig,但是没有用。 我清除了缓存并登录,然后检查了我的页面,但是没有“编辑”链接打印到该页面。

还有其他想法吗? 这样的事情可能应该在Antimatter这样的核心主题中,以使编辑者更容易快速跳转到管理员来编辑页面?

您将需要使用admin用户登录到前端。 默认情况下,由于管理员和前端会话是分开的,因此仅登录到管理员是不够的。

@rhukster 。 我使用站点管理员登录名(这是唯一的用户)登录到/ admin。 我如何登录前端? 抱歉,我是Grav的新手。

使用登录插件,请参阅自述https://github.com/getgrav/grav-plugin-login (https://github.com/getgrav/grav-plugin-login#login-page)

在回答问题时结束

感谢大家的帮助。 也许有更好的方法可以做到这一点,但这就是我最终在我的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 %}

然后在我的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;
}

如果所有主题默认都包含这样的内容,那就太好了。

也许管理插件可以包含用于编辑链接的页面变量? 模板中的代码看起来比我提供的代码好得多。

此页面是否有帮助?
0 / 5 - 0 等级

相关问题

Quy picture Quy  ·  6评论

maciejmatu picture maciejmatu  ·  3评论

artofthesmart picture artofthesmart  ·  4评论

wildafrica picture wildafrica  ·  4评论

ritchiedalto picture ritchiedalto  ·  6评论