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.

Plugins

How to set a new default frontmatter on Admin plugin

Solved by pamtbaau View solution

Started by Zwitterio 8 years ago · 4 replies · 1030 views
8 years ago

The title speak for itself. I wrote my articles on raw markdown until now, but I'm tired to copy-paste everytime the frontmatter from the previous pages, editing that and so on. So I want to make admin plugin work for me. I can write the articles on the platform (it's comfortable, really) but the copy-paste problem stay.
I've search online, on the forum, on the documentation, but I still don't know how to automatize this process.

8 years ago

I presume you would like to set some defaults to Page fields in the Admin plugin when adding a new page to your blog?

Maybe the docs on Example: Page Blueprints and Advanced Blueprint Features might give you some direction.

After extending a blueprint you can assign defaults to the existing fields and/or add your own custom fields with defaults. These defaults can even be set by functions in your theme or plugin (Using Function Calls).

Hope this helps...

PS. This suggestions is decaffeinated...

👍 1
last edited 09/28/18 by pamtbaau
8 years ago

Thanks for the tips: I was just trying to get a default frontmatter in expert mode, but if I can totally reset the form in the classical mode I'm ok too.

8 years ago Solution

When you edit a page in 'Expert' mode, there is no blueprint, you just edit the frontmatter manually.

You can 'extend' an existing blueprint and add fields to tabs, you can override fields and you can add your own tab with your required fields. And you can create a completely custom form.

The following example is taken from the First Example from the 'Example: Page Blueprints' docs. This example allows you to create a dedicated tab 'Gallery' in the Page editor in Admin containing your custom defined fields.

  • Create a file '/user/blueprints/pages/default.yaml'
  • Copy the following blueprint definition into the created file:

    YAML
    title: Gallery
    '@extends':
      type: default
      context: blueprints://pages
    
    form:
    fields:
      tabs:
        type: tabs
        active: 1
    
        fields:
          gallery:
            type: tab
            title: Gallery
    
            fields:
              header.an_example_text_field:
                type: text
                label: Add a number
                default: 5
                validate:
                  required: true
                  type: int
    
              header.an_example_select_box:
                type: select
                label: Select one of the following
                default: one
                options:
                  one: One
                  two: Two
                  three: Three
    
  • On saving the page, the following frontmatter will be generated:
    YAML
    an_example_text_field: 5
    an_example_select_box: one
    
8 years ago

Hi,
I had too many things to do in this first times of october, but I tried to pursue the way you pointed at and I surely was able to solve the problem even better than if I followed my first idea. Infact, to set a new default frontmatter you can set a series of settings in the blueprint wich are “text”-type and with a default value.
But that’s the ugly way. With blueprints I even set some options with validation (of urls, for example) and with the classical switch yes/no.
So blueprints are very useful, I’m surprised I originally missed those in the documentation.
Thanks for the advice,
Cheers

Suggested topics

Topic Participants Replies Views Activity
Plugins · by Rene, 1 week ago
2 43 1 week ago
Plugins · by Xavier, 4 weeks ago
2 53 4 weeks ago
Plugins · by Luka Prinčič, 7 years ago
3 1179 1 month ago
Plugins · by Sebastian van de Meer, 1 month ago
1 48 1 month ago
Plugins · by PIERROT Alain, 2 months ago
3 72 2 months ago