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.

Forms & Blueprints

Using templates, how to create sub-keys in the page frontmatter?

Solved by pamtbaau View solution

Started by Julien 8 years ago · 2 replies · 589 views
8 years ago

I'm trying to create a blueprint for a form that will result in a frontmatter with an additional level. Let's say this is what the result should look like:

YAML
object:
    color: blue
    width: 340

How would I go about this in the blueprint? I've only managed to get this to work by using a section to introduce the object key before being able to actually use the sub-keys, object.color and object.width:

YAML
fields:
    header.object:
        name: object
        type: section
        title: Object

        fields:
            header.object.color:
                name: color
                type: text
                label: Color

            header.object.width:
                name: width
                type: number
                label: Width

Omitting the first block (the section definition) leads to the form showing up empty. What if I don't want a section element and the title that comes with it? Is there another way to tell the blueprint: "Let's now deal with sub-keys of the object key"?

last edited 06/16/18 by Julien
8 years ago Solution

@domsson The following definition for fields in your blueprints/default.yaml will produce what you want:

YAML
[form + tab definitions omited]
fields:
  header.object.color:
    name: color
    type: text
    label: Color

  header.object.width:
    name: width
    type: number
    label: Width

It generates the following frontmatter:

YAML
object:
    color: blue
    width: 340

Hope this helps.

8 years ago

Well, this is slightly embarrassing. I tried that exact thing several times, and every time I did, the tab would not show up in the admin. After your reply, I tried one more time and guess what? It worked. Maybe I messed up the indentation when I previously tried. In any case, thanks for your working example, my issue turned out to be a non-issue. :)

Suggested topics

Topic Participants Replies Views Activity
Forms & Blueprints · by Ton Haarmans, 5 years ago
13 1135 4 months ago
Forms & Blueprints · by Hugo Oliveira, 5 months ago
0 61 5 months ago
Forms & Blueprints · by Flachy Joe, 6 months ago
9 134 6 months ago
Forms & Blueprints · by Augustus, 7 months ago
7 108 7 months ago
Forms & Blueprints · by Julien, 7 months ago
10 128 7 months ago