Default taxonomies for specific pages

First time user. Been customizing with grav for some months.

I would like to add default taxonomies to blueprints for specific pages. Found this and was so happy.

https://learn.getgrav.org/content/taxonomy#adding-custom-taxonomy-values-in-default-and-options

But I can not get it to work, is there a real-world example of a blueprint-file that someone can share and teach me ?

I have found other solutions, such as adding these values hidden, or adding fields under admin overrides below the advanced tab when using Grav Admin Plugin but as the documentation suggests I would prefer this solution.

Is it possible to specify defaults that are then editable from admin ? For example, an editor of the webpage creates a page and get’s the default values set but is then able to add (or maybe remove) categorys, tags manually.

Please share which steps you have taken and what happened. We might then better understand/reproduce the issue…

Of course. Sorry for that.

  1. Download and fresh install of Grav 1.5.6 with Admin-plugin and theme Quark on a Mac with MAMP.

  2. Edited …/user/themes/quark/blueprints/blog.yaml with the piece of code from the docs (https://learn.getgrav.org/content/taxonomy#adding-custom-taxonomy-values-in-default-and-options). The section below about “taxonomies” was added by me.

     extends@: default
     child_type: item
    
     rules:
     slug:
     pattern: "[a-z][a-z0-9_\-]+"
     min: 2
     max: 80
    
    taxonomies:
     fields:
      header.taxonomy:
       default:
        category: ['blog','page']
        tag: ['test']
       options:
        category: ['grav']
       validate:
        type: commalist
    
  3. This above file (blog.yaml) is cut in this post after my edit because I didn’t manage to paste it all as preformatted text.

  4. Made sure that taxonomies are set in site.yaml (…/system/config).

  5. Created both pages with blog or item setting.

  6. Saved the pages, returned and doublechecked both forms and frontmatter in admin (via expertmode) and finally via VSCode the Markdown files but there was no category set.

  7. I have also experimented with adding this piece of code to forms and/or advanced tab/overrides

@grelle Blueprints are not the easiest part of Grav. And especially the pickiness of Yaml on indentations, make it hard to create correct blueprints.

It is hard to judge from the snippet you copied, but it seems the definition of the blueprint needs a bit more attention… May I suggest to have a look at the documentation about Forms?

To create a correct form, follow the following steps:

  • First have a look at the default definition of ‘default.yaml’ in folder ‘/system/blueprints/pages/’. That will give an idea of the layout of the default template in Admin. Quark has extended that blueprint in ‘blog.yaml’.

  • The blueprint has the following structure:

    title: PLUGIN_ADMIN.DEFAULT
    
    rules:
      slug:
        pattern: '[a-zA-Zа-яA-Я0-9_\-]+'
        min: 1
        max: 200
    
    form:
      validation: loose
    
      fields:
    
        tabs:
          type: tabs
          active: 1
    
          fields:     <-- Below you will find the definitions for tab fields
            content:  <-- Tab definition for tab 'Content' at top of page in Admin
              type: tab
              title: PLUGIN_ADMIN.CONTENT
    
              fields:  <-- Below are the definitions for fields
                 ...
    
             options:  <-- Tab definition for tab 'Options' at top of page in Admin
                type: tab
                title: PLUGIN_ADMIN.OPTIONS
    
                fields:
                   ...
    
  • If you want the Taxonomy field in the ‘Options’ tab (as it is by default), then add the following definition right below ‘fields’ below ‘active 1’ in ‘/user/themes/quark/blueprints/blog.yaml’. That is probably line 17 in Quark v1.2.5:

    options:
      type: tab
      title: PLUGIN_ADMIN.OPTIONS
    
      fields:
        taxonomies:   <-- Copied from the example in the docs
          fields:
            header.taxonomy:
              default:
                category: ['blog','page']
                tag: ['test']
              options:
                category: ['grav']
              validate:
                type: commalist
    

Make sure you apply the right indentation…

Almost forgot… Don’t make these changes inside the Quark theme, but create an inherited theme for these changes. If you don’t you will loose the changes when Quark gets updated.

Hope this helps…

Thankyou for your kind help. I feel stupid because I can not get it to work as I understand that should work when reading the docs. My understanding is that it should keep the original “taxonomy” field and just add the default values when creating the page.

This is the whole of my …/system/blueprints/pages/default.yaml after trying my best to edit at your proposal.

title: PLUGIN_ADMIN.DEFAULT

rules:
  slug:
    pattern: '[a-zA-Zа-яA-Я0-9_\-]+'
    min: 1
    max: 200

form:
  validation: loose

  fields:

    tabs:
      type: tabs
      active: 1

      fields:
        content:
          type: tab
          title: PLUGIN_ADMIN.CONTENT

          fields:
            xss_check:
              type: xss

            header.title:
              type: text
              autofocus: true
              style: vertical
              label: PLUGIN_ADMIN.TITLE

            content:
                type: markdown
                validate:
                  type: textarea

            header.media_order:
              type: pagemedia
              label: PLUGIN_ADMIN.PAGE_MEDIA

        options:
          type: tab
          title: PLUGIN_ADMIN.OPTIONS

          fields:
            taxonomies:
              fields:
                header.taxonomy:
                  default:
                    category: ['blog','page']
                    tag: ['test']
                  options:
                    category: ['grav']
                  validate:
                    type: commalist

            publishing:
              type: section
              title: PLUGIN_ADMIN.PUBLISHING
              underline: true

              fields:
                header.published:
                  type: toggle
                  toggleable: true
                  label: PLUGIN_ADMIN.PUBLISHED
                  help: PLUGIN_ADMIN.PUBLISHED_HELP
                  highlight: 1
                  size: medium
                  options:
                    1: PLUGIN_ADMIN.YES
                    0: PLUGIN_ADMIN.NO
                  validate:
                    type: bool

                header.date:
                  type: datetime
                  label: PLUGIN_ADMIN.DATE
                  toggleable: true
                  help: PLUGIN_ADMIN.DATE_HELP

                header.publish_date:
                  type: datetime
                  label: PLUGIN_ADMIN.PUBLISHED_DATE
                  toggleable: true
                  help: PLUGIN_ADMIN.PUBLISHED_DATE_HELP

                header.unpublish_date:
                  type: datetime
                  label: PLUGIN_ADMIN.UNPUBLISHED_DATE
                  toggleable: true
                  help: PLUGIN_ADMIN.UNPUBLISHED_DATE_HELP

                header.metadata:
                  toggleable: true
                  type: array
                  label: PLUGIN_ADMIN.METADATA
                  help: PLUGIN_ADMIN.METADATA_HELP
                  placeholder_key: PLUGIN_ADMIN.METADATA_KEY
                  placeholder_value: PLUGIN_ADMIN.METADATA_VALUE

        advanced:
          type: tab
          title: PLUGIN_ADMIN.ADVANCED

          fields:
            columns:
              type: columns
              fields:
                column1:
                  type: column
                  fields:

                    settings:
                      type: section
                      title: PLUGIN_ADMIN.SETTINGS
                      underline: true

                    folder:
                      type: text
                      label: PLUGIN_ADMIN.FOLDER_NAME
                      validate:
                        rule: slug

                    route:
                      type: parents
                      label: PLUGIN_ADMIN.PARENT
                      classes: fancy

                    name:
                      type: select
                      classes: fancy
                      label: PLUGIN_ADMIN.PAGE_FILE
                      help: PLUGIN_ADMIN.PAGE_FILE_HELP
                      default: default
                      data-options@: '\Grav\Common\Page\Pages::pageTypes'

                    header.body_classes:
                      type: text
                      label: PLUGIN_ADMIN.BODY_CLASSES


                column2:
                  type: column

                  fields:
                    order_title:
                      type: section
                      title: PLUGIN_ADMIN.ORDERING
                      underline: true

                    ordering:
                      type: toggle
                      label: PLUGIN_ADMIN.FOLDER_NUMERIC_PREFIX
                      help: PLUGIN_ADMIN.FOLDER_NUMERIC_PREFIX_HELP
                      highlight: 1
                      options:
                        1: PLUGIN_ADMIN.ENABLED
                        0: PLUGIN_ADMIN.DISABLED
                      validate:
                        type: bool

                    order:
                      type: order
                      label: PLUGIN_ADMIN.SORTABLE_PAGES
                      sitemap:

            overrides:
              type: section
              title: PLUGIN_ADMIN.OVERRIDES
              underline: true

              fields:

                header.dateformat:
                  toggleable: true
                  type: select
                  size: medium
                  selectize:
                    create: true
                  label: PLUGIN_ADMIN.DEFAULT_DATE_FORMAT
                  help: PLUGIN_ADMIN.DEFAULT_DATE_FORMAT_HELP
                  placeholder: PLUGIN_ADMIN.DEFAULT_DATE_FORMAT_PLACEHOLDER
                  data-options@: '\Grav\Common\Utils::dateFormats'
                  validate:
                    type: string

                header.menu:
                  type: text
                  label: PLUGIN_ADMIN.MENU
                  toggleable: true
                  help: PLUGIN_ADMIN.MENU_HELP

                header.slug:
                  type: text
                  label: PLUGIN_ADMIN.SLUG
                  toggleable: true
                  help: PLUGIN_ADMIN.SLUG_HELP
                  validate:
                    message: PLUGIN_ADMIN.SLUG_VALIDATE_MESSAGE
                    rule: slug

                header.redirect:
                  type: text
                  label: PLUGIN_ADMIN.REDIRECT
                  toggleable: true
                  help: PLUGIN_ADMIN.REDIRECT_HELP

                header.process:
                  type: checkboxes
                  label: PLUGIN_ADMIN.PROCESS
                  toggleable: true
                  config-default@: system.pages.process
                  default:
                    markdown: true
                    twig: false
                  options:
                    markdown: Markdown
                    twig: Twig
                  use: keys

                header.twig_first:
                  type: toggle
                  toggleable: true
                  label: PLUGIN_ADMIN.TWIG_FIRST
                  help: PLUGIN_ADMIN.TWIG_FIRST_HELP
                  highlight: 0
                  options:
                    1: PLUGIN_ADMIN.YES
                    0: PLUGIN_ADMIN.NO
                  validate:
                    type: bool

                header.never_cache_twig:
                  type: toggle
                  toggleable: true
                  label: PLUGIN_ADMIN.NEVER_CACHE_TWIG
                  help: PLUGIN_ADMIN.NEVER_CACHE_TWIG_HELP
                  highlight: 0
                  options:
                    1: PLUGIN_ADMIN.YES
                    0: PLUGIN_ADMIN.NO
                  validate:
                    type: bool

                header.child_type:
                  type: select
                  toggleable: true
                  label: PLUGIN_ADMIN.DEFAULT_CHILD_TYPE
                  default: default
                  placeholder: PLUGIN_ADMIN.USE_GLOBAL
                  data-options@: '\Grav\Common\Page\Pages::types'

                header.routable:
                  type: toggle
                  toggleable: true
                  label: PLUGIN_ADMIN.ROUTABLE
                  help: PLUGIN_ADMIN.ROUTABLE_HELP
                  highlight: 1
                  options:
                    1: PLUGIN_ADMIN.ENABLED
                    0: PLUGIN_ADMIN.DISABLED
                  validate:
                    type: bool

                header.cache_enable:
                  type: toggle
                  toggleable: true
                  label: PLUGIN_ADMIN.CACHING
                  highlight: 1
                  options:
                    1: PLUGIN_ADMIN.ENABLED
                    0: PLUGIN_ADMIN.DISABLED
                  validate:
                    type: bool

                header.visible:
                  type: toggle
                  toggleable: true
                  label: PLUGIN_ADMIN.VISIBLE
                  help: PLUGIN_ADMIN.VISIBLE_HELP
                  highlight: 1
                  options:
                    1: PLUGIN_ADMIN.ENABLED
                    0: PLUGIN_ADMIN.DISABLED
                  validate:
                    type: bool

                header.debugger:
                  type: toggle
                  toggleable: true
                  label: PLUGIN_ADMIN.DEBUGGER
                  help: PLUGIN_ADMIN.DEBUGGER_HELP
                  highlight: 1
                  options:
                    1: PLUGIN_ADMIN.ENABLED
                    0: PLUGIN_ADMIN.DISABLED
                  validate:
                    type: bool

                header.template:
                  type: text
                  toggleable: true
                  label: PLUGIN_ADMIN.DISPLAY_TEMPLATE

                header.append_url_extension:
                  type: text
                  label: PLUGIN_ADMIN.APPEND_URL_EXT
                  toggleable: true
                  help: PLUGIN_ADMIN.APPEND_URL_EXT_HELP

            routes_only:
              type: section
              title: PLUGIN_ADMIN.ROUTE_OVERRIDES
              underline: true

              fields:

                header.routes.default:
                  type: text
                  toggleable: true
                  label: PLUGIN_ADMIN.ROUTE_DEFAULT

                header.routes.canonical:
                  type: text
                  toggleable: true
                  label: PLUGIN_ADMIN.ROUTE_CANONICAL

                header.routes.aliases:
                  type: array
                  toggleable: true
                  value_only: true
                  size: large
                  label: PLUGIN_ADMIN.ROUTE_ALIASES


            admin_only:
              type: section
              title: PLUGIN_ADMIN.ADMIN_SPECIFIC_OVERRIDES
              underline: true

              fields:

                header.admin.children_display_order:
                  type: select
                  label: PLUGIN_ADMIN.ADMIN_CHILDREN_DISPLAY_ORDER
                  help: PLUGIN_ADMIN.ADMIN_CHILDREN_DISPLAY_ORDER_HELP
                  toggleable: true
                  classes: fancy
                  default: 'collection'
                  options:
                    'default': 'Ordered by Folder name (default)'
                    'collection': 'Ordered by Collection definition'


                header.order_by:
                  type: hidden

                header.order_manual:
                  type: hidden
                  validate:
                    type: commalist

                blueprint:
                  type: blueprint

I did try with the original “taxonomies” code present and removed, it does produce the same result. I did remove it because VSCode with YAML plugin from RedHat warned me about “duplicate key”.

The result is, original taxonomy fields are gone in admin, and there is a single row (see screenshot) with input field at the top of “options” tab without label and no predefined data, neither any options…

There is also no default set data in frontmatter for the pages I create.

Thankyou for your heads-up on creating childtheme and so on, I’m aware of that. Right now I’m just stuck on a as far as I can see pretty basic feature :slight_smile:

@grelle, I may have lead you astray by referring to ‘/system/blueprints/pages/default.yaml’ as a point of reference…

The blueprint ‘/user/themes/quark/blueprints/blog.yaml’ is derived from ‘default.yaml’ and therefor you need to know how ‘default.yaml’ looks like and what you are ‘extending’…

The changes should however be made in the derived blueprint ‘/user/themes/quark/blueprints/blog.yaml’ as you correctly started out with in your step 2.

By ‘extending’ a parent blueprint, the child inherits the definitions of the parent and extends on those definitions. Since you made the changes to the parent, you have deleted some essential definitions, like section information (the title ‘Taxonomies’) and definitions of the field ‘header.taxonomy’ itself…

Bonus:
After you have mastered applying changes in Quark, you might want to take up the challenge of making the changes in your inherited theme… You might be suprised how trimmed that blueprint will look like.

No problem, we are moving forward :slight_smile:

Did apply the change to '/user/themes/quark/blueprints/blog.yaml´like this:

extends@: default
child_type: item

rules:
  slug:
    pattern: "[a-z][a-z0-9_\-]+"
    min: 2
    max: 80

form:
  fields:
    tabs:
      type: tabs
      active: 1

      fields:
        taxonomies:
          fields:
            header.taxonomy:
              default:
                category: ['blog','page']
                tag: ['test']
              options:
                category: ['grav']
              validate:
                type: commalist

        advanced:
          fields:
            overrides:
              fields:
                header.child_type:
                  default: item
        blog:
          type: tab
          title: Blog Config

          fields:

            content_title:
              type: spacer
              title: Content Definition

            header.content.items:
              type: textarea
              yaml: true
              label: Items
              default: '@self.children'
              validate:
                type: yaml

            header.content.limit:
              type: text
              label: Max Item Count
              default: 5
              validate:
                required: true
                type: int
                min: 1

            header.content.order.by:
              type: select
              label: Order By
              default: date
              options:
                folder: Folder
                title: Title
                date: Date
                default: Default

            header.content.order.dir:
              type: select
              label: Order
              default: desc
              options:
                asc: Ascending
                desc: Descending

            header.content.pagination:
              type: toggle
              label: Pagination
              highlight: 1
              default: 1
              options:
                1: PLUGIN_ADMIN.ENABLED
                0: PLUGIN_ADMIN.DISABLED
              validate:
                type: bool

            header.content.url_taxonomy_filters:
              type: toggle
              label: URL Taxonomy Filters
              highlight: 1
              default: 1
              options:
                1: PLUGIN_ADMIN.ENABLED
                0: PLUGIN_ADMIN.DISABLED
              validate:
                type: bool

          import@:
            type: partials/blog-bits
            context: blueprints://pages

Then went to admin and created a blog page which had the original taxonomy fields back but no predefined data, neither any options.

From the markdown-file of blog page:

---
title: blog100
content:
    items:
        - '@self.children'
    limit: 5
    order:
        by: date
        dir: desc
    pagination: true
    url_taxonomy_filters: true
---

Created an “item” page too just for testing. No predefined (deafult) data there either…

Did I apply the changes to blog.yaml in the wrong way ? Or have I completely misunderstood the way default values should apply to “Taxonomy” ?

@grelle You might want to take a good look at the structure of the changes you have made. You are missing out the definition for the tab…

I discovered that, made changes accordingly. Cleared Grav cache (which is set to off though). Cleared webbrowser-cache. Refreshed admin and created a new blog page…

No change

'/user/themes/quark/blueprints/blog.yaml´

extends@: default
child_type: item

rules:
  slug:
    pattern: "[a-z][a-z0-9_\-]+"
    min: 2
    max: 80

form:
  fields:
    tabs:
      type: tabs
      active: 1

      options:
        fields:
          taxonomies:
            fields:
              header.taxonomy:
                default:
                  category: ['blog','page']
                  tag: ['test']
                options:
                  category: ['grav']
                validate:
                  type: commalist

      advanced:
        fields:
          overrides:
            fields:
              header.child_type:
                default: item
      blog:
        type: tab
        title: Blog Config

        fields:

          content_title:
            type: spacer
            title: Content Definition

          header.content.items:
            type: textarea
            yaml: true
            label: Items
            default: '@self.children'
            validate:
              type: yaml

          header.content.limit:
            type: text
            label: Max Item Count
            default: 5
            validate:
              required: true
              type: int
              min: 1

          header.content.order.by:
            type: select
            label: Order By
            default: date
            options:
              folder: Folder
              title: Title
              date: Date
              default: Default

          header.content.order.dir:
            type: select
            label: Order
            default: desc
            options:
              asc: Ascending
              desc: Descending

          header.content.pagination:
            type: toggle
            label: Pagination
            highlight: 1
            default: 1
            options:
              1: PLUGIN_ADMIN.ENABLED
              0: PLUGIN_ADMIN.DISABLED
            validate:
              type: bool

          header.content.url_taxonomy_filters:
            type: toggle
            label: URL Taxonomy Filters
            highlight: 1
            default: 1
            options:
              1: PLUGIN_ADMIN.ENABLED
              0: PLUGIN_ADMIN.DISABLED
            validate:
              type: bool

        import@:
          type: partials/blog-bits
          context: blueprints://pages

I’m a bit puzzled about blog.yaml though. It has a section with a tab setting with title: “Blog config”. That is not showing up in my admin of any of my pages.

      blog:
        type: tab
        title: Blog Config

I guess I should see that to confirm I’m in the right place searching for my taxonomy fields…

EDIT: Now I see that this is stuff that is being set in frontmatter but not editable in admin.

EDIT: This section was not visible in admin most probably of some error in my blueprint, I now see it after I managed to correctly set my blueprint.

@grelle I guess that at some point, staring any longer at code doesn’t make us see what is staring in our face…

When fields have sub-fields, they have a ‘fields’ property that contains the definitions of the sub-fields: ‘Tabs’ and ‘Tab’ are such a fields…

Example from the docs on Tabs/Tab:

tabs:
  type: tabs
  active: 1

  fields:             <-- Containing the list of tabs (sub-fields)
    content:          <-- Start of definition of tab 'Content'
      type: tab
      title: PLUGIN_ADMIN.CONTENT

      fields:         <-- Containing the list of fields on tab 'Options'

        # .... other subfields

I now managed to get i to work! Fantastic. Thankyou for your patience!

This is my ‘/user/themes/quark/blueprints/blog.yaml’ which adds default values and options!

extends@: default
child_type: item

rules:
  slug:
    pattern: "[a-z][a-z0-9_\-]+"
    min: 2
    max: 80

form:
  fields:
    tabs:
      type: tabs
      active: 1

      fields:

        advanced:
          fields:
            overrides:
              fields:
                header.child_type:
                  default: form

        options:
          fields:
            taxonomies:
              fields:
                header.taxonomy:
                  default:
                    category: ['my-category']
                    tag: ['my-tag']
                  options:
                    tag: ['option-1','option-2','option-3']
                  validate:
                    type: commalist

        blog:
          type: tab
          title: Blog Config

          fields:

            content_title:
              type: spacer
              title: Content Definition

            header.content.items:
              type: textarea
              yaml: true
              label: Items
              default: '@self.children'
              validate:
                type: yaml

            header.content.limit:
              type: text
              label: Max Item Count
              default: 5
              validate:
                required: true
                type: int
                min: 1

            header.content.order.by:
              type: select
              label: Order By
              default: date
              options:
                folder: Folder
                title: Title
                date: Date
                default: Default

            header.content.order.dir:
              type: select
              label: Order
              default: desc
              options:
                asc: Ascending
                desc: Descending

            header.content.pagination:
              type: toggle
              label: Pagination
              highlight: 1
              default: 1
              options:
                1: PLUGIN_ADMIN.ENABLED
                0: PLUGIN_ADMIN.DISABLED
              validate:
                type: bool

            header.content.url_taxonomy_filters:
              type: toggle
              label: URL Taxonomy Filters
              highlight: 1
              default: 1
              options:
                1: PLUGIN_ADMIN.ENABLED
                0: PLUGIN_ADMIN.DISABLED
              validate:
                type: bool

          import@:
            type: partials/blog-bits
            context: blueprints://pages

@grelle Celebrate the solution as long as it lasts… The next release of Quark will wipe it.

I will :slight_smile: Thankyou for making it clear again. I and my fellow co-first-timers will of course apply this to an inherited customized theme.