How to create default FrontMatter for my Docs pages

first-time

#1

Greetings all, long-time lurker, first-time poster. Thanks to everyone for making this a great community!

I’m struggling with creating some default FrontMatter that’ll auto-insert into new docs.md pages that are created.
Basically, I’m using the Learn2 theme (like the GRAV documentation site uses) which has those big blue chevrons on either side of a page, allowing the user to easily advance forward and backward in the documentation.

To do that, I simply need the following FrontMatter on a page:
taxonomy: category: docs
Simple enough. But I’d like my child theme to be able to set that by default anytime someone creates a new docs.md page.

I’m lost on how to do this, and hoping a kind soul in the forums can point me in the right direction.
Thanks in advance!
Bill


#2

Hi @1GoodCall, I do this type of thing in my Open Course Hub Skeleton. Here is an earlier response to a very similar question, New pages with default frontmatter

You may also want to check out my Learn2 with Git Sync skeleton which includes this technique as well:

Let me know how things go.


#3

Thanks for the quick response Paul,

I’m actually using your Learn2 with Git Sync theme—nice work!
Even more awesome I’m talking directly with you about it in the forums.
Further proof that GRAV is a great CMS.

So it sounds like I need to do this via the blueprints—>docs.yaml file? Like this?
title: Docs
@extends’:
type: default
context: blueprints://pages

form:
fields:
tabs:

  fields:
    content:
      type: tab

      fields:
        
        frontmatter: 
            default: 
                taxonomy:
                    category: docs

        content:
            markdown: true
            default: "Your page content goes here."

    advanced:
      fields:
        overrides:
          fields:
            header.visible:
              default: 1

I’m I on the right path? Sorry, this flat-file stuff is all new to me, but I am loving it!
Thanks for your help.


#4

Hi @1GoodCall, welcome to Grav🙂

Yes you are on the right track (but no ‘frontmatter:’ item) but I myself should also be setting that taxonomy by default but I am not… yet! Give me a bit of time and I will share here what I can come up with.


#5

Thanks, @paulhibbitts, that’s awesome!

I agree it was scratching my head as to why the theme didn’t have this set as a default, seems logical for it to be so. Learn2 doesn’t have it yet either, which is where the problem starts I guess.

Also, as a side note, I like to keep a list of 3rd party contractors that I farm jobs out to from time to time. Would you like me to add you to my list and send quote requests for GRAV that I may have? I’m asking because I’ve found from experience that folks like you who are active in system forums are usually rock-solid contractors who are good to work with.


#6

Still working on this, thought I had a solution…

BTW, I am a educator/interaction designer so my dev skills are quite limited but thanks for the kind thoughts! If you are ever looking for dev help with Grav you could try the Grav Slack room https://getgrav.org/slack


#7

Cool! I work in Education (higher ed) too! I’ve found GRAV to be an excellent tool to teach students with as well—and makes student portfolio type projects so easy and portable!

Thanks for the Slack link, I think I’ll join that.

I thought I had this fixed serval times already, and finally realized I didn’t have a clue what I was doing, which lead me here. Thank you for your assistance!


#8

SOLVED!

Many Thanks to @paulhibbitts for the solution here. Here’s what was done to get it working—hope this helps others in the future:

  1. In your Learn2 or Learn2-GitSync theme navigate to the blueprints folder. Technically it could be any theme that you need some default FrontMatter for.
  2. Copy the docs.yaml file and place it in your custom child theme (recommended, here’s how to make one) blueprints folder — or edit directly (might be lost later on theme update tho).
  3. Update the file to look like this:
title: Docs
'@extends':
    type: default
    context: blueprints://pages

form:
  fields:
    tabs:

      fields:
        content:
          type: tab
          fields:
            content:
                markdown: true
                default: "Your page content goes here."

        options:
          fields:
            header.taxonomy.category:
              type: hidden
              label: Default Taxonomy Category
              default: [docs]
  1. This is the code that makes the magic happen and auto adds the proper taxonomy category to every new page’s FrontMatter on save. Remember, you won’t see it until you save the page and come back to it:
default code...


       options:
          fields:
            header.taxonomy.category:
              type: hidden
              label: Default Taxonomy Category
              default: [docs]


...rest of code

That’s It! ~Enjoy

Thanks @paulhibbitts for your work on this. I’m sure many will find it useful.

Please Note:

This technique will not allow for users to add any other taxonomy categories, which could be a good thing depending on content