Skip to content
Grav 2.0 is officially stable. Read the announcement →

Community guidelines

Please keep discussions civil and on-topic. Repeated violations may lead to a temporary ban.

Content & Markdown

Frontmatter global setting for Default page

form

Started by Mikula Beutl 7 years ago · 2 replies · 965 views
7 years ago

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

7 years ago

@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:

    YAML
    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...

5 years ago

For grav v1.7.23 there is already a form field for page access.

We can override this in /user/blueprints/pages/default.yaml with

YAML
'@extends':
  type: default
  context: blueprints://pages

form:
  fields:
    tabs:
      fields:
        security:
          fields:
            _site:
              fields:
                header.access:
                  default:
                    site.login: true
👍 1

Suggested topics

Topic Participants Replies Views Activity
Content & Markdown · by Jochen, 8 months ago
6 99 8 months ago
Content & Markdown · by Ton Haarmans, 1 year ago
10 186 1 year ago
Content & Markdown · by Jan L'Am, 1 year ago
4 148 1 year ago
Content & Markdown · by Leonardo, 1 year ago
3 62 1 year ago
Content & Markdown · by belthasar, 1 year ago
4 257 1 year ago