Frontmatter global setting for Default page

form

#1

i searched the entire help center
I could not find what i was looking for, basically i need to know where i would set the following frontmatter “global” for each new Default page created:

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

I don’t want any page accessible without login, for now I am manually adding the 3 lines to each new page i create but i want those 3 lines included from the start already, i could not find the config file to set this default behaviour to…

Please help,
thx mik


#2

@mikulabc If you are using the Admin panel to create pages, the following might be a solution. If you create pages manually using an editor I would not know of any Grav solution.

Grav allows you to extend the blueprints used by Admin to generate pages. Have a look at the docs on Page Blueprints.

In the following example, a new section ‘Access’ with two new fields will be added to the bottom of tab ‘Advanced’. The defaults are being set to ‘true’. Every time a page is created using Admin panel, the two fields are added to the frontmatter of the page.

  • Create file '/user/blueprints/pages/default.yaml
  • Add the following to the page:
    title: Access
    '@extends':
        type: default
        context: blueprints://pages
    
    form:
      fields:
        tabs:
          type: tabs
          active: 1
    
          fields:
            advanced:
              fields:
                access:
                  type: section
                  title: Access
                  underline: true
                  fields:
                    header.access.site.login:
                      type: toggle
                      label: Site login
                      highlight: 1
                      default: 1
                      options:
                          1: PLUGIN_ADMIN.ENABLED
                          0: PLUGIN_ADMIN.DISABLED
                      validate:
                          type: bool
                    header.access.site.admin:
                      type: toggle
                      label: Site admin
                      highlight: 1
                      default: 1
                      options:
                          1: PLUGIN_ADMIN.ENABLED
                          0: PLUGIN_ADMIN.DISABLED
                      validate:
                          type: bool
    

Off course, you can place the section/fields somewhere else e.g another tab.

Hope this helps…