Add extra page headers automatically to every page

I want to protect every page so that every unregistered user can not view the pages, unless they login.

I know there is a private plugin, but I do not want to use this, I just want to use the login plugin for this.
So, I need to add the following ags to every page:

access:
site.login: true
admin.login: true

But can this be added automatically every time I add a new page? Do I need to change something in the theme? I am using the learn2 theme.

Do you mean when a Page is added via the Admin Panel? With a custom Blueprint I think you should be able to set defaults for those values: https://learn.getgrav.org/forms/blueprints/example-page-blueprint

Hello Paul,

Yes, when I create a new page via the default template, I want to have added the following (in bold):

title: 'Title of my page’
access:
site.login: true
admin.login: true

I presume I need to change the default.html.twig, but I do not know where to put exactly these fields:

{% embed 'partials/base.html.twig' with { github_link_position: false } %}

    {% block sidebar %}
    <nav id="sidebar">
        <div id="header-wrapper">
            <div id="header">
                <a id="logo" href="{{ theme_config.home_url ?: base_url_absolute }}">{% include 'partials/logo.html.twig' %}</a><br>
                {% include 'partials/search.html.twig' %}
            </div>
        </div>
        {% include 'partials/sidebar.html.twig' %}
    </nav>
    {% endblock %}

    {% block content %}
        {% include 'partials/page.html.twig' %}
    {% endblock %}

    {% block footer %}{% endblock %}

{% endembed %}

I’ve looked into this a bit more and while I was hoping a Blueprint change would do what you want it does not look like page access items are there by default. A custom Blueprint might still be an option, but I’ve not done anything re: access rights and Blueprints myself.

Hi Paul,

Thanks for your effort.

Regards,

 Raf

Hello,

I found a solutions, but it is a tweak in Grav and probably will be undone when Grav is updated. Maybe there is a better way.

I edited the file /var/www/ictdocs.ap.be/system/blueprints/pages/default.yaml and added, above line 210.

header.access:
type: checkboxes
label: PLUGIN_ADMIN.ACCESS
help: PLUGIN_ADMIN.ACCESS_HELP
toggleable: true
config-default@: system.pages.access
default:
site.login: true
admin.login: true
options:
site.login: Site Login
admin.login: Admin Login
use: keys

Also I have edited the /var/www/ictdocs.ap.be/user/plugins/admin/languages/en.yaml and added, above line 264:

ACCESS: “Restrict Access”
ACCESS_HELP: “Enables access restrictions controlled by the login plugin”

Then you see:

I only need to find a way to enable this option by default.

Regards,

Raf

Looks like you are making progress @rvreugde! You should be able to define the default right in that Blueprint you are editing, at least I would think so.

More info here : https://learn.getgrav.org/forms/blueprints/fields-available#common-fields-attributes and sample blueprint setting default value here: https://learn.getgrav.org/forms/blueprints/example-page-blueprint#a-first-example

So maybe default: true instead of config-default@: system.pages.access to force it on by default?

Any news ? I would like to do the same for access.site data.